// Carousel functions:
function setCategory(category, subcategory, noredirect) {
	// Now. Are we on the homepage?
	
	var url = String(document.location.pathname);
	
	if (url == '/' || url == '/index.php' || url == '/vases.php' || noredirect) {	
		// See note below. noredirect means that we've come from a rewritten URL, so we want
		// to update the carousel instead of redirecting...
	
		if (thisMovie("carousel")) {
	  	if (thisMovie("carousel").loadCategory) {
	   		// This handles an error that crops up if we try to setCategory
	 	 		// before the Flash has loaded. It's a short-term fix, though
	 	 		// -- discuss a proper resolution with Komodo.
	 	 		thisMovie("carousel").loadCategory(category, subcategory);

	 	 		setBreadcrumb(category,subcategory);	 	 		
	 	 	}
		}
	}
	
	else if (!noredirect) {
		// If we're not on the homepage, redirect to index.php with querystring values
		// Note that we can DISABLE the redirect by passing in noredirect
		// We do this if we've redirected to the homepage via an .htaccess mod rewrite
		// such as, RewriteRule ^tryflowers.org.uk/colour$ /index.php?category=colour&mod_rewrite [QSA,L]
		// In those cases, we don't want to redirect again -- we want to stay where we were
				
		document.location = '/index.php?category='+category+'&subcategory='+subcategory;	
	}
  return false;
}

function setBreadcrumb(category,subcategory) {
	var breadcrumb = '';
	if (category == 'colour') {
		breadcrumb += 'Pick a colour';	
	}
	else if (category == 'occasion') {
		breadcrumb += 'Pick an occasion';	
	}
	else if (category == 'style') {
		breadcrumb += 'Find your own style';	
	}
	else if (category == 'room') {
		breadcrumb += 'Pick a room';	
	}
	else if (category == 'video') {
		breadcrumb += 'Ideas on video';		
	}
	else if (category == 'vase') {
		breadcrumb += 'Vases and containers';		
	}
	else if (category == 'me') {
		breadcrumb += 'My flower ideas';	
	}
	else if (category == 'month') {
		breadcrumb += 'Flower idea of the month';	
	}
	else if (category == 'search') {
		breadcrumb += 'Search results';	
	}
	
	if (subcategory && (category != 'me' && category != 'month')) {
		breadcrumb += ' &gt; '+subcategory;	
	}
	if (breadcrumb) $j('#breadcrumb').html(breadcrumb);

}

function setOrder(param) {
    thisMovie("carousel").orderFlowers(param);    
    return false;
}

function setView(view) {
    if (view == 'Carousel') {
	    thisMovie("carousel").carouselView();	
    }
    else if (view == 'Gallery') {
	    thisMovie("carousel").galleryView();	
    }
    return false;
}

function outputFromFlash(param){
//	alert("Flash says Hi " + param);
	idea(param);
}

function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	}
	else {
		return document[movieName];
	}
}

