/*
*	GLOBAL JS CODE HERE
*/
$(function(){
	
	/* PNG FIX */
	$(document).pngFix();

	
	/* COLOR BOX POPUP (http://colorpowered.com/colorbox/) */
	$(".colourbox").colorbox({
		iframe:true,
		innerWidth: 623,
		innerHeight: 615,
		title : true,
		scrolling : false
	});
	
	
	/*	Product Popups */
	$("#productsList .product .colourbox,#calloutBoxes .colourbox").colorbox({
		iframe:true,
		innerWidth: 623,
		innerHeight: 615,
		title : true,
		scrolling : false
	});
	
	$("#productsList .product .colourbox,.colourbox").colorbox({
		onClosed:function(){
			location.reload();
			
		}
	});
			
	
	/* COLOR BOX POPUP (http://colorpowered.com/colorbox/) */
	$("#viewWishlist,#PrintCompleteRange").colorbox({
		iframe:true,
		innerWidth: 925,
		innerHeight: 636,
		title : true,
		scrolling : false
	});
	
	
	
	/*
	*	Flash Replacement of header
	*/
	
	var $sFlashContainer = $('#pageChild').attr('class');
	var $sFlashFile = '/flash/'+$sFlashContainer+'.swf';

	var so = new SWFObject($sFlashFile, "movie", "900", "334", "8", "#A5A5b3");

	so.addParam("scale", "noscale");
	so.addParam("quality", "high");
	so.addParam("menu", "false");
	so.addParam("salign", "LT");
	so.addParam("wmode", "transparent");
	so.write("flashReplaced");
				
				
				
	
	
	
	/* CUFON FONT REPLACEMENT
	Generate More (here(http://cufon.shoqolate.com/generate/) */
	Cufon.replace('.vag-rounded-bold', { fontFamily: 'vag-rounded-bold',hover: true });


	/* POPUP EVENT (replacement for target="_blank") */
	$( ".popup" ).live( "click", function( event ) {
		event.preventDefault();
		var sTarget = $( this ).attr( "href" );
		var iWidth = 1024;
		var iHeight = 768;
		var iScrollbars = 2;
		var iLeft = (screen.width)?(screen.width-iWidth)/2:100;
		var iTop = (screen.height)?(screen.height-iHeight)/2:100;
		var sSettings='width='+iWidth+',height='+iHeight+',top='+iTop+',left='+iLeft+',scrollbars='+iScrollbars+',location=yes,directories=no,status=yes,menubar=yes,toolbar=yes,resizable=yes';
		win=window.open( sTarget, "", sSettings );
	} );
	

	//	Scream Js Animation
	var oScream = $("#pageChild .scream");
	if(oScream != null || oScream != undefined){
		var oScreamPos = oScream.position();
		if(oScreamPos != null){
			var iOriginalPos = oScreamPos.left;
			
			//	Move scream for Animation
			oScream.css('left', iOriginalPos + 100);
			oScream.animate({left: iOriginalPos+'px'}, 1500, "easeOutElastic", function() {});
			}
	}
	
	
	
	
	
	//	Quote Animation
	var oQuote = $("#header .quote");
	if(oQuote != null || oQuote != undefined){
		var oQuotePos = oQuote.position();
	
		var iOriginalQuotePos = oQuote.css("bottom") 
		
		//	Move Quote for Animation
		oQuote.css('bottom', -100);

		oQuote.animate({
		bottom: iOriginalQuotePos
	
	  }, 1000, "easeOutBack", function() {
			//	Profit Share, its free animation
			$oItsFree = $('.itsFreeStar');
			
			$oItsFree.animate({
			width: 73,
			height: 73,
			left: 310
			
			}, 1000, "easeOutElastic");
  	});
		
		
	}
	
	





	//	Call out boxes Animation

	$oCallOutBoxes = $('#calloutBoxes .inner a');
	$iCallOuts = $oCallOutBoxes.length;
	
	$iFirstbox = $oCallOutBoxes.eq(0);
	$iFirstbox .css("left",0);
	callOutBoxes($iFirstbox);
	



	//	Profit Share Slider
	
	$('#proftShareScroller .products').cycle({ 
		fx:     'scrollHorz', 
		speed:  'normal', 
		timeout: 0, 
		next:   '#next', 
		prev:   '#prev' 
	});
	
	
	
});
	




/*
*	FUNCTIONS
*/


//	Animates the callout boxes
function callOutBoxes($this){
	//	Wait then Animate of Screen to left
	$this.delay(2500).animate({
		left: -200
	
	  }, 750, function() {
			//	Reset Position of item
			$this.css("left",200);
			
			// Current Element Index
			$iPosition = $this.index() + 1;
			
			//	Set NExt Object to move
			if($iPosition >= $iCallOuts)
				$oNext = $oCallOutBoxes.eq(0);
			else
				$oNext = $this.next();
			
	
			//	Move next item to start postition and repeat
			$oNext.animate({left: 0}, 
				1500, "easeOutQuint", function() {
					callOutBoxes($oNext);
				}
			);  
	  });
}




//	See if file exists for flash header
function file_exists (url) {
    // Returns true if filename exists  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/file_exists    // +   original by: Enrique Gonzalez
    // +      input by: Jani Hartikainen
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %        note 1: This function uses XmlHttpRequest and cannot retrieve resource from different domain.
    // %        note 1: Synchronous so may lock up browser, mainly here for study purposes.     // *     example 1: file_exists('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm');
    // *     returns 1: '123'
    var req = this.window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) {
        throw new Error('XMLHttpRequest not supported');    }
 
    // HEAD Results are usually shorter (faster) than GET
    req.open('HEAD', url, false);
    req.send(null);    if (req.status == 200) {
        return true;
    }
 
    return false;
}
