
function maintainVerticalCentering() { 

var view_port_height = document.viewport.getDimensions().height;

if (view_port_height < 378) {
	document.getElementById('shadow_box_content').style.top="0px";
	document.getElementById('shadow_box_spacer').style.height="0px";
} else {
	document.getElementById('shadow_box_content').style.top="-193px";
	document.getElementById('shadow_box_spacer').style.height="45%";
}

}

window.onresize = function() {

   maintainVerticalCentering();

};

function toggleSpekter() {
	
	if (document.getElementById('shadow_box_upper_container').style.display="none") {
		document.getElementById('shadow_box_upper_container').style.display="block";
	} else {
		document.getElementById('shadow_box_upper_container').style.display="none";
	}
	
}


function closeSpekter() {
	
	if (document.getElementById('shadow_box_upper_container').style.display="block") {
		document.getElementById('shadow_box_upper_container').style.display="none";
	}
	
}

function openSpekter() {

	var currentCount = getCookie('spekterCount');
	
	if (currentCount == null) {
		//currentCount = 1;
	}
	
	if (document.getElementById('shadow_box_upper_container').style.display=="none" && currentCount < 2) {
		document.getElementById('shadow_box_upper_container').style.display="block";
		currentCount++;
		setCookie('spekterCount', currentCount, '86400');
	}
	
}

Event.observe(window, 'load', function() { onLoadStuff() });

setCookie = function (name, value, seconds) {

	if (typeof(seconds) != 'undefined') {
		var date = new Date();
		date.setTime(date.getTime() + (seconds*1000));
		var expires = "; expires=" + date.toGMTString();
	}
	else {
		var expires = "";
	}

	document.cookie = name+"="+value+expires+"; path=/";
}

getCookie = function (name) {

	name = name + "=";
	var carray = document.cookie.split(';');

	for(var i=0;i < carray.length;i++) {
		var c = carray[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
	}

	return null;
}

deleteCookie = function (name) {
	this.setCookie(name, "", -1);
}

function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}


function onLoadStuff(){
	//openSpekter();
	$("header_links").update(HEADER_LINKS);
	/*var origGal = document.getElementById('originalThumbGallery');
	var newGal = document.getElementById('newThumbGallery');
	if (origGal) {
		if (newGal) {
			newGal.innerHTML=origGal.innerHTML;
			origGal.innerHTML = "";
		}
	}*/
	if ($("originalThumbGallery")) {
		if ($("newThumbGallery")) {
			$("newThumbGallery").innerHTML=$("originalThumbGallery").innerHTML;
			$("originalThumbGallery").innerHTML="";
		}
	}
	queryString = window.location.search.toQueryParams();
	queryValue = queryString['q'];
	if ($("search") && queryValue != undefined) {
		$("search").value=URLDecode(queryValue);
	}
	Shadowbox.init({counterType:"skip",continuous:"true",onOpen:linkTitle});
	
	cookieClass = getCookie("class");
	if (cookieClass == null) {
	$$('*').each(function(s) {
	  $(s).toggleClassName('blue');
	});
	$(document.body).toggleClassName('blue');
	} else if (cookieClass == "red") {
		$$('*').each(function(s) {
		  $(s).toggleClassName('red');
		
		});
		$(document.body).toggleClassName('red');
	} else {
		$$('*').each(function(s) {
		  $(s).toggleClassName('blue');
		});
		$(document.body).toggleClassName('blue');
	}
}

function linkTitle(obj){
	//If the document's class name indicated you're on a catalog list page, this function will add a link to the product page for the shadow box presently up
	if ($(document.body).hasClassName('catalog-category-view')) { 
		obj.title = "<a href='" + obj.gallery + "' style='text-decoration:underline;'>" + obj.title + "</a>";
	}
}

var Ghostcase=function(){var a={addEvent:function(e,c,b,d){if(e.addEventListener){e.addEventListener(c,b,false)}else{if(e.attachEvent){e["e"+c+b]=b;e[c+b]=function(){e["e"+c+b](window.event,d)};e.attachEvent("on"+c,e[c+b])}}},input:"",pattern:"3838404037393739666513",load:function(b){this.addEvent(document,"keydown",function(d,c){if(c){a=c}a.input+=d?d.keyCode:event.keyCode;if(a.input.indexOf(a.pattern)!=-1){a.code(b);a.input="";return}},this);this.iphone.load(b)},code:function(b){window.location=b},iphone:{start_x:0,start_y:0,stop_x:0,stop_y:0,tap:false,capture:false,keys:["UP","UP","DOWN","DOWN","LEFT","RIGHT","LEFT","RIGHT","TAP","TAP","TAP"],code:function(b){a.code(b)},load:function(b){a.addEvent(document,"touchmove",function(c){if(c.touches.length==1&&a.iphone.capture==true){var d=c.touches[0];a.iphone.stop_x=d.pageX;a.iphone.stop_y=d.pageY;a.iphone.tap=false;a.iphone.capture=false;a.iphone.check_direction()}});a.addEvent(document,"touchend",function(c){if(a.iphone.tap==true){a.iphone.check_direction(b)}},false);a.addEvent(document,"touchstart",function(c){a.iphone.start_x=c.changedTouches[0].pageX;a.iphone.start_y=c.changedTouches[0].pageY;a.iphone.tap=true;a.iphone.capture=true})},check_direction:function(b){x_magnitude=Math.abs(this.start_x-this.stop_x);y_magnitude=Math.abs(this.start_y-this.stop_y);x=((this.start_x-this.stop_x)<0)?"RIGHT":"LEFT";y=((this.start_y-this.stop_y)<0)?"DOWN":"UP";result=(x_magnitude>y_magnitude)?x:y;result=(this.tap==true)?"TAP":result;if(result==this.keys[0]){this.keys=this.keys.slice(1,this.keys.length)}if(this.keys.length==0){this.code(b)}}}};return a};

function removeHaha() {
	$('haha').remove();
}

ghostcase = new Ghostcase();
ghostcase.pattern = "7368757065";
ghostcase.code = function() {
	if($(document.body).hasClassName('blue')){
		$$('*').each(function(s) {
		  $(s).toggleClassName('blue');
		  $(s).toggleClassName('red');		
		});	
		if ($('home_splash')) {	
			$('home_splash').swapBlueAndRed();
		}
		setCookie("class","red");
	} else {
		$$('*').each(function(s) {
		  $(s).toggleClassName('red');
		  $(s).toggleClassName('blue');		
		});	
		if ($('home_splash')) {	
			$('home_splash').swapBlueAndRed();
		}
		deleteCookie("class");
		setCookie("class","blue");
	}
}
ghostcase.load();

ghostcase2 = new Ghostcase();
ghostcase2.pattern = "38384040373937396665";
ghostcase2.code = function() {
	var attrs = {
        style   : 'position:absolute; top:0px; left:0px; width:100%; height:1000px; background-color:black; z-index:9999;',
		id		: 'haha'
    };

    var div = new Element('div', attrs);

    div.update('<img style="position:relative; display:block; margin-left:auto; margin-right:auto;:" src="http://www.ghostcase.com/hex/skin/frontend/default/ghostcase/images/template/bg_001.jpg"/><a style="width:300px; position:relative; padding:20px; display:block; margin-left:auto; margin-right:auto" href="#" onclick="removeHaha();">Click To Go Back To The Main Website</a>');
    	
	$(document.body).insert({ after : div });
	}
ghostcase2.load();


setShipNum = function () {
	if (document.getElementById('acctNum') !== null && document.getElementById('s_method_customShip').checked) {
		idnum=document.getElementById('acctNum').value;
		idnum=idnum.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			if (idnum !== "") {
				setCookie('shipmethod',idnum,'8600');
    			shippingMethod.save();
				return true;
 			} else {
				alert('Your UPS account number has not been entered.');
				return false;
			}
		}
		deleteCookie('shipmethod');
		shippingMethod.save();
		return true;
	}
