/////// TOGGLE LOADING OF CATALOG////////////
var snow = "assets/xml/snow.xml";
var dirt = "assets/xml/dirt.xml";
var flashvars = {};
var path = location.hash;

function flashPutHref(href) { location.href = href; }

function selectCatalog() {
	//location.search = "";
	if(path.match('snow')){
		loadCatalog(snow);
	}else{
		loadCatalog(dirt);
	}
}


function loadProdMovie (content, title)
{
	//alert("url = "+url+", title = "+title);
	 Shadowbox.open({
        content:    "http://www.viddler.com/player/"+content+"&autoplay=t",
        player:     "swf",
        title:      title,
		width: 		"545",
		height:		"349"
    });
}

function loadInline (content, title, width, height)
{
	Shadowbox.open({
        content:    content,
        player:     "inline",
        title:      title,
		width: 		width,
		height:		height
    });
}

function popup(text)
{
	alert(text);
}
// Called when snow/dirt tabs are clicked
function loadCatalog(catalog) {
	//Important step!! This trick is here following the instuctions for SlideShowPro here: http://wiki.slideshowpro.net/SSPfl/C-DynamicallyAssignXML
	//This event handler is called from the containing html page when user clicks on dirt/snow tabs i.e. onclick='loadCatalog(snow)' or (dirt)
	//The dirt and snow variables are paths to the dirt and snow xml files and are assigned at the top of this library
	//Using this method, content for the flash file can be assigned dynamically rather then hard coded at the time the swf is published = much more flexible
	flashvars.xmlfile = catalog;
	flashvars.initialURL = escape(document.location);
	//conditional check of what catalog is being called
	if (catalog == dirt) {
		//this jQuery handler finds the h2 tag with the id='gearHeading' and changes the inner display text to Dirt Gear
		$('#gearHeading').text("Dirt Gear");
		//jQuery handler - finds the element with id='header_wrapper' and reassigns the CSS background property so that the dirt jpeg is displayed.
		$('#header_wrapper').css('backgroundImage','url(assets/css/images/header_dirt.jpg)');
		//same trick here as above - dynamically switching out the tab graphic at top of page
		$('#top_nav').css('backgroundImage','url(assets/css/images/nav/dirt_top_tab.gif)');
	} else {
		//this jQuery handler finds the h2 tag with the id='gearHeading' and changes the inner display text to Snow Gear
		$('#gearHeading').text("Snow Gear");
		$('#header_wrapper').css('backgroundImage','url(assets/css/images/header_snow.jpg)');
		$('#top_nav').css('backgroundImage','url(assets/css/images/nav/snow_top_tab.gif)');
	}
	
	var params = {};
	params.loop = "false";
	params.quality = "high";
	params.wmode = "opaque";
	params.allowScriptAccess = "sameDomain";
	var attributes = {};
	attributes.align = "middle";
	swfobject.embedSWF("klimgallery_flat.swf", "myAlternativeContent", "840", "590", "8.0.0", "assets/js/swfobject/expressInstall.swf", flashvars, params, attributes);
}

function tabImageSwap (catalog)
{
	if (catalog == dirt) {
		//this jQuery handler finds the h2 tag with the id='gearHeading' and changes the inner display text to Dirt Gear
		$('#gearHeading').text("Dirt Gear");
		//jQuery handler - finds the element with id='header_wrapper' and reassigns the CSS background property so that the dirt jpeg is displayed.
		$('#header_wrapper').css('backgroundImage','url(assets/css/images/header_dirt.jpg)');
		//same trick here as above - dynamically switching out the tab graphic at top of page
		$('#top_nav').css('backgroundImage','url(assets/css/images/nav/dirt_top_tab.gif)');
	} else {
		//this jQuery handler finds the h2 tag with the id='gearHeading' and changes the inner display text to Snow Gear
		$('#gearHeading').text("Snow Gear");
		$('#header_wrapper').css('backgroundImage','url(assets/css/images/header_snow.jpg)');
		$('#top_nav').css('backgroundImage','url(assets/css/images/nav/snow_top_tab.gif)');
	}
}

/////////////// HIDE/SHOW TROUBLESOME FLASH ELEMENTS WHEN THICKBOX IS OPENED///////////////

// called before ThickBox is opened
function fc_PreProcess() {
	toggleTroublesomeElements(false);
	return true;
	
}
// called when ThickBox close button is clicked
function fc_BuildFoxyCart() {
	toggleTroublesomeElements(true);
}

var toggleTroublesomeElements = function(on){
        var vis = (on ? 'visible' : 'hidden');
        var selects = document.getElementsByTagName('select');
        for(i = 0, len = selects.length; i < len; ++i){
            selects[i].style.visibility = vis;
        }
        var objects = document.getElementsByTagName('object');
        for(i = 0, len = objects.length; i < len; ++i){
            objects[i].style.visibility = vis;
        }
        var embeds = document.getElementsByTagName('embed');
        for(i = 0, len = embeds.length; i < len; ++i){
            embeds[i].style.visibility = vis;
        }
};

//preload some of the interface graphics to stop image flashing or gaps
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}