/*****************************************************
 *	STIXELJOCKEYS SCRIPTS
 *****************************************************
 *
 *****************************************************/

var TETRIS_COLUMNIZER = new TetrisColumnizer(0,0,"alert");
TETRIS_COLUMNIZER.addColumn(181);
TETRIS_COLUMNIZER.addColumn(181, 12);
TETRIS_COLUMNIZER.addColumn(181, 12);
TETRIS_COLUMNIZER.addColumn(181, 12);

window.onload = function(){

	TETRIS_COLUMNIZER.addEventListener("changeContentRightHeight", TETRIS_COLUMNIZER.EVENT_END);
	TETRIS_COLUMNIZER.play();

	var objLoader = new Image();
	objLoader.src = "img/dashloader.gif";

};

$(document).ready(function(){

	/* add submits */
	$("form[@name=notify]").submit(function(){notify();return false;});
	$("form[@name=notify] > a.subscribeNotify").click(function(){notify();return false;});
});

/*****************************************************
 *	GUI
 *****************************************************/

function isBrowserSupported(){
	return(typeof(document.getElementById) != "undefined");
}

//*** set the class of contentLeft
function changeContentLeftClass(strClass){
	if(isBrowserSupported()){
		document.getElementById("contentLeft").className = strClass;
	}
}

function changeContentRightHeight(intHeight){
	if(isBrowserSupported()){
		var objRight = document.getElementById("contentRightText");
		objRight.style.height = intHeight +"px";

		//***	change left accordingly
		self.resizeBottomObjects();
	}
}

function activateShopPage(strId, strType){
	if(ACTIVE_SHOPPAGE[0] != strId){
		if(ACTIVE_SHOPPAGE[0] != ""){
			document.getElementById(ACTIVE_SHOPPAGE[0]).className = "s"+ ACTIVE_SHOPPAGE[1];
		}
		ACTIVE_SHOPPAGE = new Array(strId, strType);
		document.getElementById(ACTIVE_SHOPPAGE[0]).className = "s"+ ACTIVE_SHOPPAGE[1] +"Active";
	}
}


/*****************************************************
 *	NOTIFIER
 *****************************************************/

function notify(){

	//*** check e-mail
	var objEmail = $("form[@name=notify] > input[@name=email]").val();
	if(typeof(objEmail) == "string" && echeck(objEmail)){

		//*** show loader
		$("#notifyLoader").show();

		//*** post and alert

		  $.ajax({
			url: "inc/subscribeNotify.php",
			type: "POST",
			dataType: "html",
			data: {email: objEmail},
			complete:function(){$("#notifyLoader").hide(200);},
			success: function(objResult){alert(objResult);},
			error: function(objErr){alert("There was an error during the subscription! Please try again.");}
		  });
	}else{
		alert("Please enter a valid emailaddress!");
	}
}

/*****************************************************
 *	CONVENIENCE
 *****************************************************/

function shirtsBySJNumber(intMain, intSub, intSJId){

}

function echeck(str) {
	var objReg = /[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	var matched = str.match(objReg);

	if(matched){
		if(matched.length == 1){
			return true;
		}

	}
	return false;
}

/*****************************************************
 *	VERTICAL SCALING
 *****************************************************/

var MIN_LEFT_HEIGHT = 386;
var BOTTOM_OBJECT_OFFSET = 217;//*** height of top and 3 horizontal white spaces
var BOTTOM_OBJECT_WRAPPER = "contentRightText"
var arrBO = new Array("contentLeft");//arrBottomObjects


function resizeBottomObjects(){
	if(document.getElementById){
		var i=0;
		var hl = MIN_LEFT_HEIGHT;

		if(document.getElementById(BOTTOM_OBJECT_WRAPPER).clientHeight + BOTTOM_OBJECT_OFFSET > document.getElementById("body").clientHeight){
			hl = document.getElementById(BOTTOM_OBJECT_WRAPPER).clientHeight;
		}else{
			hl = document.getElementById("body").clientHeight - BOTTOM_OBJECT_OFFSET;
		}

		if(hl < MIN_LEFT_HEIGHT){hl=MIN_LEFT_HEIGHT;}//*** keep a minimum height

		if(hl >= 0){
			while(i<arrBO.length){
				var hi = parseInt(document.getElementById(arrBO[i]).style.height);
				if(hl!=hi){
					document.getElementById(arrBO[i]).style.height = hl +"px";
				}
				i++;
}	}	}	}

window.onresize = function(){
	self.resizeBottomObjects();
}
