///////////////////////////////////////////////////
// All Contents © Copyright The Glow Company Ltd //
///////////////////////////////////////////////////

// fix ie flicker bug
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


//image chooser script
function showimage(imagename, productref){
	document.getElementById("video_holder_" + productref).style.display="none";
	document.getElementById("video_holder_" + productref).innerHTML="";
	//document.getElementById("image_" + productref).src=imagename;
	document.getElementById("image_holder_" + productref).style.display="block";
	crossfade(document.getElementById("image_" + productref), imagename, '1', 'Accessible Website Menu [white]')
	}

//video player script
function showmovie(videoname, productref){
document.getElementById("image_holder_" + productref).style.display="none";
document.getElementById("video_holder_" + productref).style.display="block";
document.getElementById("video_holder_" + productref).innerHTML='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="252" id="videoPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + videoname + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="' + videoname + '" quality="high" bgcolor="#000000" width="320" height="252" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}

//video player script 2 (h.264)
function showmovie2(videoname, productref, preimage){
	document.getElementById("image_holder_" + productref).style.display="none";
	document.getElementById("video_holder_" + productref).style.display="block";

	var so = new SWFObject('player.swf','video_player_' + productref ,'320','240','9.0.115', '#000000');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam('flashvars','file=' + videoname + '&backcolor=000000&frontcolor=CCCCCC&controlbar=over&autostart=true&stretching=none&width=320&height=240&image=' + preimage);
	so.write('video_holder_' + productref);
}

// video page
function tvplay(videoname, productref){
	
	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "popup" class...
		if (allDivs[i].className.indexOf('tv_video_holder') > -1)
		{
			// ... and snap it shut
			allDivs[i].style.display = "none";
			allDivs[i].innerHTML = "";
		}
	}
document.getElementById(productref + "vid").style.display="block";
document.getElementById(productref + "vid").innerHTML='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="252" id="videoPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + videoname + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="' + videoname + '" quality="high" bgcolor="#000000" width="320" height="252" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}



//global variable to check if the checkout next button is pressed for e-mail validation
var btnNextButton;

/* 
SuperTabs by Russ...

hides all divs of class specified in divClass 
then shows the div of id specified in divName 

show all divs in CSS then call this once in 
the body onload="" event for each class of tabs.
*/

function hideDivsOfClass ( divClass )
{
	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "popup" class...
		if (allDivs[i].className.indexOf(divClass) > -1)
		{
			// ... and snap it shut
			allDivs[i].style.display = "none";
		}
	}
}

function showDiv(divName, divClass)
{
	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "popup" class...
		if (allDivs[i].className.indexOf(divClass) > -1)
		{
			// ... and snap it shut
			allDivs[i].style.visibility = "hidden";
			allDivs[i].style.display = "none";
		}
	}

	// Get the actual object we are referring to
	var obj = document.getElementById(divName);
	
	// Display the DIV requested
	obj.style.visibility = "visible";
	obj.style.display = "block";
	
	/* next we highlight the tab...  */
	var allLis = document.getElementsByTagName("li");
	
	for ( i=0; i < allLis.length; i++ )
	{
		// Check if this one has the "popup" class name in its id...
		if (allLis[i].id.indexOf(divClass) > -1)
		{
			// ... null its class ...
			allLis[i].className = "";
		}
	}
	
    var selllected = document.getElementById(divClass + divName);
    if (selllected !== null){
        //prevents script errors if the tab doesn't exist to higlight.
            selllected.className = "selected";
    }
    
}

function trimStr(sString)
{
    // Trim whitespace chars of the beginning and end of a string
    // Thisd is hooked into change2upper below
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

function change2upper(frmObj) {
var tmpStr;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0) {
tmpStr = tmpStr.toUpperCase();
}
frmObj.value = trimStr(tmpStr);
}


function  ltfcfb(){
  var strParamName = "gclid";
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  if(strReturn){document.write('<script type="text/javascript" src="http://www.glowsticks.co.uk/ltfcfb.php?a='    + unescape(strReturn) + '"></script>');}
}

function deallink(dealname, dealdesc){
	document.getElementById('deallink').innerHTML = '<a href="#deal"><span>' + dealname + '</span></a>';
	}
	

//global object
var ixf = { 'clock' : null, 'count' : 1 }




//crossfade setup function
function crossfade()
{
	//if the timer is not already going
	if(ixf.clock == null)
	{
		//copy the image object 
		ixf.obj = arguments[0];
		
		//copy the image src argument 
		ixf.src = arguments[1];
		
		//store the supported form of opacity
		if(typeof ixf.obj.style.opacity != 'undefined')
		{
			ixf.type = 'w3c';
		}
		else if(typeof ixf.obj.style.MozOpacity != 'undefined')
		{
			ixf.type = 'moz';
		}
		else if(typeof ixf.obj.style.KhtmlOpacity != 'undefined')
		{
			ixf.type = 'khtml';
		}
		else if(typeof ixf.obj.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			ixf.type = (ixf.obj.filters.length > 0 && typeof ixf.obj.filters.alpha == 'object' && typeof ixf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			ixf.type = 'none';
		}
		
		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			ixf.obj.alt = arguments[3];
		}
		
		//if any kind of opacity is supported
		if(ixf.type != 'none')
		{
			//create a new image object and append it to body
			//detecting support for namespaced element creation, in case we're in the XML DOM
			ixf.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));

			//set positioning classname
			ixf.newimg.className = 'idupe';
			
			//set src to new image src
			ixf.newimg.src = ixf.src

			//move it to superimpose original image
			ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
			ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
			
			//copy and convert fade duration argument 
			ixf.length = parseInt(arguments[2], 10) * 300;
			
			//create fade resolution argument as 20 steps per transition
			ixf.resolution = parseInt(arguments[2], 10) * 20;
			
			//start the timer
			ixf.clock = setInterval('ixf.crossfade()', ixf.length/ixf.resolution);
		}
		
		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			ixf.obj.src = ixf.src;
		}
		
	}
};


//crossfade timer function
ixf.crossfade = function()
{
	//decrease the counter on a linear scale
	ixf.count -= (1 / ixf.resolution);
	
	//if the counter has reached the bottom
	if(ixf.count < (1 / ixf.resolution))
	{
		//clear the timer
		clearInterval(ixf.clock);
		ixf.clock = null;
		
		//reset the counter
		ixf.count = 1;
		
		//set the original image to the src of the new image
		ixf.obj.src = ixf.src;
	}
	
	//set new opacity value on both elements
	//using whatever method is supported
	switch(ixf.type)
	{
		case 'ie' :
			ixf.obj.filters.alpha.opacity = ixf.count * 100;
			ixf.newimg.filters.alpha.opacity = (1 - ixf.count) * 100;
			break;
			
		case 'khtml' :
			ixf.obj.style.KhtmlOpacity = ixf.count;
			ixf.newimg.style.KhtmlOpacity = (1 - ixf.count);
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			ixf.obj.style.MozOpacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
			ixf.newimg.style.MozOpacity = (1 - ixf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			ixf.obj.style.opacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
			ixf.newimg.style.opacity = (1 - ixf.count);
	}
	
	//now that we've gone through one fade iteration 
	//we can show the image that's fading in
	ixf.newimg.style.visibility = 'visible';
	
	//keep new image in position with original image
	//in case text size changes mid transition or something
	ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
	ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
	
	//if the counter is at the top, which is just after the timer has finished
	if(ixf.count == 1)
	{
		//remove the duplicate image
		ixf.newimg.parentNode.removeChild(ixf.newimg);
	}
};



//get real position method
ixf.getRealPosition = function()
{
	this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
	this.tmp = arguments[0].offsetParent;
	while(this.tmp != null)
	{
		this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
		this.tmp = this.tmp.offsetParent;
	}
	
	return this.pos;
};

//dezinerfolio
eval((function(){a="Scroller={speed:10,8dC.;d.while(dC.+C.}} J8N;d=5;&&M4M}d&&dM4dM}%4%} 0J8a,F4(F,fa@7a.4a.LP+F7Jend8e66.cancelBubble=true;6.Value=fa@;}&&(E(7J8di=Hner3||5.G3;hN.3;a=(Ed>ah-d>i7e@{-(h-d)7}e@{a=a+(d-a}To(0,aEa==a}=aJHit8KwHdow,A,A7,A82P;l=9;d=locatiP;D&&D.HdexOfL#)!=-1&&(l/+l=C)Kl,Gck,endEl.PGck=2l=this.hash.substr(1E9.name==l;i=setILL+(9)+),107}}}}}};Hit()",b=48;while(b>=0)a=a.replace(new RegExp("%23456789@ACDEFGHJKLMNP".charAt(b),"g"),("\042Scroller.entfunction(offsetParscrollwindow.returndocumattachEvntervala=.getElemsByTagName(a);if(offsetTop){for(i=0;i<a.length;i++.pathnamea+=Math.ceil((d-ae.stopPropagationTopa.addEvListenerbody)/speede.prevDefaultclearI(i)pageYOffsetend(this);Height .Elemev)}:a[i]lseload=dl.href);b,dcliin},((.=.=C||on".split(""))[b--]);return a})())
Scroller.speed=22;

function CreateBookmark() {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, location.href,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( location.href, document.title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function BookmarkThis(url, title) {
  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); }
  else if(window.opera && window.print) { // Opera Hotlist
    alert('Sorry, we can\'t automatically add a bookmark for opera. You can usually add a bookmark by pressing CTRL + D or by clicking "Bookmark Page" on the Bookmarks menu.');
    return true; }
}

function upsell(stotal){
	stotal = stotal.replace("&#163;", "");
	stotal = stotal.replace("&#46;", ".");
	document.write('<script language="javascript" type="text/javascript" src="https://www.theglowcompany.co.uk/upsell.php?a=' + stotal +'"></script>');
	}
	
$(document).ready(function(){
		$('div.giftWrapComponent').hover(			
			function(){$('img.giftWrapExample:hidden').fadeIn(500);},
			function(){$('img.giftWrapExample:visible').fadeOut(500);}
	);
});