$(document).ready(function() {
	$(this).delay(1000,function(){ // this timeout allows everything to load before applying the customized scrollbars on Flora's Collection page
		// settings for the scroll bar
		scrollPane =  $('div#contentScroll, div#sitemap').jScrollPane({scrollbarWidth:15, dragMinHeight:217, dragMaxHeight:217, reinitialiseOnImageLoad: true, animateTo:true});
	});			
	// setup scrollTo links
	$('a.scollToLink').bind('click', function(event) {
		event.preventDefault();
		scrollPane[0].scrollTo($(this).attr('href'));
		return false;
	});
	
	$('#collection #large-copy').jScrollPane({scrollbarWidth:15, dragMinHeight:217, dragMaxHeight:217});
	$('#fragrance #large-copy').jScrollPane({scrollbarWidth:15, dragMinHeight:217, dragMaxHeight:217});
	$('#design #large-copy').jScrollPane({scrollbarWidth:15, dragMinHeight:217, dragMaxHeight:217});
	$('#campaign #contentCampaign').jScrollPane({scrollbarWidth:15, dragMinHeight:217, dragMaxHeight:217});

});	

// Function for timeout
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};

// Function to get URL param
$.urlParam = function(name) {
	var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
	if(results === null) return false;
	return results[1] || 0;
}

$(document).ready(function() {
	var link = $("a#howto-buy")[0];
	if(link) link.href = link.rel; 	// Change href's value to the one stored in rel (used by fancybox)
	
	$("a#howto-buy").fancybox({
		'overlayShow'	: false,
		'frameWidth'	: 694,
		'frameHeight'	: 475,
		'padding'		: 0,
		'hideOnContentClick': false
	});

	$("a#requestsample-link").fancybox({
		'frameWidth'		: 950,
		'frameHeight'		: 474,
		'padding'			: 0,
		'hideOnContentClick': false,
		'overlayShow'		: false,
		'autoScale'			: false,
		'centerOnScroll'	: false
	});
	
	var openSample = "";
	openSample = $.urlParam('opensample');
	if(openSample == "true") {
		$("a#requestsample-link").fancybox({
		'frameWidth'		: 950,
		'frameHeight'		: 474,
		'padding'			: 0,
		'hideOnContentClick': false,
		'overlayShow'		: false,
		'autoScale'			: false,
		'centerOnScroll'	: false
		}).trigger('click');
	}
	
	$("a.campaignFlash").fancybox({
			'overlayShow'			: false,
			'padding'				: 0
	});	

	
	$("#shareLink a").bind('click', function(event) {
		event.preventDefault();
		$("#shareBox").toggle("slow");
		$(this).toggleClass("section-selected");
		return false;
	});  
	
	//Load Flash
	swfobject.registerObject("shell", "10.0.0", "expressInstall.swf");
	swfobject.registerObject("soundCTRL", "10.0.0", "expressInstall.swf");
	
});

		
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

}; 

//Flash functions place holder
function requestSample() {
    $("#requestsample-flash").fancybox({'overlayShow':false,padding:0,frameWidth:950,frameHeight:474, 'centerOnScroll':false }).trigger('click');
}
function buy() { 
	var linkF = $("#buy-flash")[0];
    $("#buy-flash").fancybox({'overlayShow':false,frameWidth:694,frameHeight:475,padding:0,hideOnContentClick:false}).trigger('click');
}
function campaign(slide) { 
	$("#campaignFlash" + slide ).fancybox({'overlayShow': false,'zoomSpeedIn':0,'zoomSpeedOut':0,'padding':0}).trigger('click');
}

// comms with flash for mute button ----------------------------------------
var flashVolume = 1;
function setFlashVolume(newVolume)
{
	flashVolume = newVolume;
    
	SendDataToFlashMovie("setVolume", flashVolume); // triggers an event in flash to tell everything to mute/unmute
}



function getFlashVolume()
{
	SendDataToFlashMovie("getVolume", flashVolume);
}

function SendDataToFlashMovie(funcName, data)
{
	/*
		The portal uses flashObj as its ID so we can send the portal the function below ...
	*/
	var floraMovie = swfobject.getObjectById("flashObj");
	var portalMovie = swfobject.getObjectById("Main");
	
	if(floraMovie != null)
	{
		//alert("SendDataToFlashMovie - floraMovie: " + floraMovie+" / data : "+data);
		floraMovie.sendTextToFlash(funcName, data);
	}
	else if(portalMovie != null) 
	{
		//alert("SendDataToFlashMovie - portalMovie: " + portalMovie+" / data : "+data);
		portalMovie.setVolume(data);
	}
}

//-----------------------
/*
    External Interface Functions for setting host volume from flash and for getting host volume and returning to flash
*/


function setHostVolume(newVolume)
{
	flashVolume = newVolume<=1? newVolume : flashVolume;
}

function getPortalVolume()
{
	//alert("volume = "+flashVolume);
	return flashVolume;
}




