var _isMacFirefox = (navigator.userAgent.indexOf("Firefox")>=0 && navigator.platform.indexOf("Mac")>=0);
var _isIE6 = (navigator.userAgent.indexOf("MSIE 6.0")>=0);
var _dirPath = location.href;
_dirPath = _dirPath.substring(0, _dirPath.lastIndexOf("/")+1);

function resizeSWFHeight(nHeight) {
	if(document.getElementById("flashcontent"))
		document.getElementById("flashcontent").style.height = nHeight;
}

function resizeSWFWidth(nWidth){
	if(document.getElementById("flashcontent"))
		document.getElementById("flashcontent").style.width = nWidth;
}

var _minSiteWidth = 1000;

function adjustSWF() {
	if(document.body.clientWidth <= _minSiteWidth){
		resizeSWFWidth(''+_minSiteWidth+'px');
	}else{
		resizeSWFWidth('100%');
	}
}

function onLoadEvents(){
	adjustSWF();
}

window.onload = onLoadEvents;


// Popups
function popUpNewsLetter(){
	popUp("newsletter");
}

function popUpSendToFriend(){
	popUp("stf");
}

function popUp(area){
	swfLocation = "gh_sendToFriend.swf";
	if(area=="newsletter")
		swfLocation = "gh_newsletterSignUp.swf";
	
	if(_isMacFirefox)
		killSWFS(true);
 	
	var popUp = new Element('div', {'id': 'popUpContainer'}).injectInside(document.body);
	
	var so = new SWFObject(swfLocation, "gethairapyPopUp", "100%", "100%", "8", "#000000");
	if(_isMacFirefox==false)
		so.addParam('wmode', 'transparent');
	so.addVariable('serverPath',_dirPath);
	so.addVariable("linkURL", location.href);
	if(location.href.indexOf("stylingstudio_video") >= 0){
		so.addVariable("sendCode", "2");
	}else if(location.href.indexOf("stylingstudio_makeover") >= 0){
		so.addVariable("sendCode", "3");
	}else{
		so.addVariable("sendCode", "1");
	}
	so.write("popUpContainer");
}

function animateInSignUp(){
	var container = $('formAnim');
	container.setOpacity(0);
	var myEffects = new Fx.Styles(container, {duration: 800, transition: Fx.Transitions.linear});
	myEffects.start({'opacity': [0, 1], 'left':[0]});
}

function animateOutSignUp(){
	var myEffects = new Fx.Styles($('hideOverlay'), {duration: 500, transition: Fx.Transitions.linear});
	myEffects.start({'opacity': [1, 0]});
}

function closePopUp(){
	//animateOutSignUp();
	(function(){
		$('popUpContainer').remove();
		if(_isMacFirefox)
			killSWFS(false);
	}).delay(100);
}

function killSWFS (turnOn)
{
	var exceptions = "gethairapyPopUp";
	var elements = $A(document.getElementsByTagName('object'));
	elements.extend(document.getElementsByTagName(window.ie ? 'select' : 'embed'));
	elements.each(function(el){
		if (exceptions.indexOf(el.id)<0)
		{
			if (turnOn){
				el.lbBackupStyle = el.style.visibility;
				el.style.visibility = 'hidden';
			}else{
				if(typeof(el.lbBackupStyle)=="undefined")
					el.lbBackupStyle = "visible";
				el.style.visibility = el.lbBackupStyle;
			}
		}
	});
}

/**********************
	- get GET Variables from the location 
	
	To Retrieve:
	ex. var ID = GETVars.GET["id"];
**********************/
var GETVars = {
	
	GET: [],
	
	load: function() {
		
		var g = this;
		
		var sGet = window.location.search; 
		if (sGet) { 
			sGet = sGet.substr(1); 
			var sNVPairs = sGet.split("&"); 
			for (var i = 0; i < sNVPairs.length; i++) { 
				var sNV = sNVPairs[i].split("="); 
				var sName = sNV[0]; 
				var sValue = sNV[1]; 
				g.GET[sName] = sValue; 
			}
		}
		
	}
	
};

GETVars.load();
