size = "medium";

var isIE9 = false;
var browser=navigator.appName;
var b_version=navigator.appVersion;
if(browser=="Microsoft Internet Explorer") 
{ 
	var version=b_version.split(";"); 
	var trim_Version=version[1].replace(/[ ]/g,""); 
	
	if(trim_Version == "MSIE9.0") {
		isIE9 = true;
	}
}

		
function chgSize(type){
	sizes = new Array("small", "medium", "large");
	if( type=="small" || type=="medium" || type=="large" )	size = type;
	else	return false;

	var sizeText = document.getElementById(size + "_size").value;
	document.getElementById("item").value =  document.getElementById(size + "_id").value;
	document.getElementById("size_text").innerHTML = sizeText + (sizeText.match(/x/)?"":"&quot;");
	document.getElementById("price").innerHTML = "$" + document.getElementById(size + "_price").value;
	//updateSubtotal();
	for(i=0;i<sizes.length;i++){
		if (document.getElementById("image_" + sizes[i]) == null)
			continue;
		document.getElementById("image_" + sizes[i]).src = "../images/landing/but_" + sizes[i] + ".png";
		document.getElementById("image_" + sizes[i]).onMouseOver = "this.src = '../images/landing/but_" + sizes[i] + "_on.png'";
		document.getElementById("image_" + sizes[i]).onMouseOut = "this.src = '../images/landing/but_" + sizes[i] + ".png'";
	}
	document.getElementById("image_" + type).src = "../images/landing/but_" + type + "_in.png";
	document.getElementById("image_" + type).onMouseOver = "";
	document.getElementById("image_" + type).onMouseOut = "";
	return false;
}

function shipping_date(type){
	tday = new Date();
	if( type == 'standard'){
		image = 'url(../images/shipping/shipping_home_std.jpg)';
		date = getNextNBizDay(tday, 6);
	}
	else if(type == 'express'){
		image = 'url(../images/shipping/shipping_home_exp.jpg)';
		date = getNextNBizDay(tday, 3);
	}
	else{
		return false;
	}
	document.getElementById("s_wkday").innerHTML = WEEK_STR[date.getDay()];
	document.getElementById("s_month").innerHTML = MONTH_STR[date.getMonth()];
	document.getElementById("s_date").innerHTML = date.getDate();
	document.getElementById('shipping_date').style.background = image;
	return false;
}

/*
function chgTab(num){
	tabs = new Array("info_wording", "info_product", "info_shipping");
	
	//document.getElementById("info_wording_right").style.background = "url(../images/landing/info_mid_tab_unselected.jpg)";
	//document.getElementById("info_product_right").style.background = "url(../images/landing/info_mid_tab_unselected.jpg)";
	for(i=1;i<=3;i++){
		document.getElementById("info_body_" + i).style.display = "none";
		document.getElementById(tabs[i-1]).className = "info_tab";
	}
	document.getElementById("info_body_" + num).style.display = "block";
	document.getElementById(tabs[num-1]).className = "info_tab in";
	if(num==2){
		document.getElementById("info_wording").className = "info_tab inleft";
	}
	else if(num==3){
		document.getElementById("info_product").className = "info_tab inleft";
	}
	return false;
}
*/

function chgTab(num){
	if(num < 1 || num > 3)	return false;
	track = new Image();
	track.src = "../images/landing/clicktab_" + num + ".gif" + "?r=" + Math.random();
	$("product_extra_info_top").style.background = "url(../images/landing/info_top_" + num + ".jpg)";
	for(i=1;i<=3;i++){
		$("info_body_" + i).style.display = "none";
	}
	$("info_body_" + num).style.display = "block";
	if(arguments.length == 1)	scrollToTab();
	
	return false;
}


function scrollToTab(){
	interval = 20;
	px = document.all?"":"px";
	pageH = document.documentElement.scrollHeight || document.body.scrollHeight;
	scrH = document.documentElement.clientHeight || document.body.clientHeight;
	tab_pos = 439;
	tab_pos = (pageH - scrH > tab_pos)?tab_pos:(pageH-scrH);
	
	myScroll = function(){
		scroll_top = document.documentElement.scrollTop || document.body.scrollTop;
		if( tab_pos - scroll_top < 10 ) return;
		step = (tab_pos - scroll_top)/10;
		window.scroll( 0, scroll_top + step );
		setTimeout(myScroll, interval);
	};
	myScroll();
}

function updateSubtotal(){
	sprice = parseFloat(document.getElementById(size + "_price").value);
	if(document.getElementById("yes").checked)	sprice += 10;
	qnt = document.getElementById('qnt_input').value;
	if( qnt == "" )	qnt = 1;
	else			qnt = parseFloat(qnt);
	//document.getElementById('subtotal').innerHTML = "$" + (sprice * qnt).toFixed(2);
}

function personalizeIt(type){
	t_type = 'PAS';
	if( arguments.length >=1 )	t_type = type;
	id = document.getElementById(size+"_id").value;
	window.location.href = "http://www.diyawards.com/diy.php?action=diy&type=wizard&templatetype=" + t_type + "&id=" + id;
	return false;
}

function outBtn(type){
	if(type == size)	return false;
	document.getElementById("image_" + type).src = "../images/landing/but_" + type + ".png";
}

function overBtn(type){
	if(type == size)	return false;
	document.getElementById("image_" + type).src = "../images/landing/but_" + type + "_on.png";
}

var magnifying = false;
var maskWidth = 325 / 3;
var maskHeight = 368 / 3;
var mImageWidth = 270 * 3;
var mImageHeight = 368 * 3;
var imageWidth = 291;
var imageHeight = 393;

function setMagnify(maskW, maskH, mImageW, mImageH){
	maskWidth = maskW;
	maskHeight = maskH;
	mImageWidth = mImageW;
	mImageHeight = mImageH;
	
	if( !document.all){
		maskW += "px";
		maskH += "px";
		mImageW += "px";
		mImageH += "px";
	}
	$("dragImage").style.width =  maskW;
	$("dragImage").style.height = maskH;
	$("bImg").style.width = mImageW;
	$("bImg").style.height = mImageH;
	
}

function moveLens(event){
	try{
		var itop, ileft;
		moving = true;
		ev = event || window.event;
		style = $("dragImage").style;
		style.display = "block";
		//style.cursor = "pointer";
		if( !document.all){
			if( ev.target == $("aImg") ){
				ileft = ev.layerX - maskWidth/2;
				itop = ev.layerY - maskHeight/2;
			}
			else if( ev.target == $("dragImage") ){
				ileft = $("dragImage").offsetLeft + ev.layerX - maskWidth/2;
				itop = $("dragImage").offsetTop + ev.layerY - maskHeight/2 ;
			}
		}
		else{
			if( ev.srcElement == $("aImg") ){
				ileft = ev.offsetX - maskWidth/2;
				itop = ev.offsetY - maskHeight/2;
			}
			else if( ev.srcElement== $("dragImage") ){
				ileft = $("dragImage").offsetLeft + ev.offsetX - maskWidth/2;
				itop = $("dragImage").offsetTop + ev.offsetY - maskHeight/2;
			}
		}
		if( itop < 0 )	itop = 0;
		else if( itop > Math.floor(imageHeight - maskHeight -2 -14 ) )	itop = Math.floor(imageHeight - maskHeight -2-14);
		if( ileft < 0 )	ileft = 0;
		else if( ileft > Math.floor(imageWidth - maskWidth -1  ) )	ileft = Math.floor(imageWidth - maskWidth -2);
		
		margintop = (-mImageWidth/imageWidth) * $("dragImage").offsetTop;
		marginleft = (-mImageHeight/imageHeight) * $("dragImage").offsetLeft;
		//marginleft = -300;
		
		//$("testDiv").innerHTML = "ileft:"+ileft+",itop:"+itop+"<br/>marginleft:"+marginleft+",margintop:"+margintop;
		
		if( !document.all || isIE9){
			itop += "px";
			ileft += "px";
			margintop += "px";
			marginleft += "px";
		}
		style.top = itop;
		style.left = ileft;
		
		$("bImg").style.marginLeft = marginleft;
		$("bImg").style.marginTop = margintop;
	}
	catch(e){
		//alert("len");
	}
}


function evolve(id, chgs, times, interval, following){
	for(i=0;i<=times;i++){
		code = "obj = $('" + id + "');" ;
		for (j=0;j<chgs.length;j++){
			step = (chgs[j].to - chgs[j].from)/times;
			if( chgs[j].attr == "opacity"){
				code += " obj.style.filter = 'alpha(opacity=" + 100 * (chgs[j].from + step*i).toFixed(1) + ")'; ";
				code += " obj.style.opacity= '" + (chgs[j].from + step*i).toFixed(1) + "'; ";
			}
			else if( chgs[j].attr == "width" || chgs[j].attr == "height" || chgs[j].attr == "left" || chgs[j].attr == "top"){
				code += " obj.style." + chgs[j].attr + "= '" + (chgs[j].from + step*i).toFixed(1) + "px'; ";
			}
			else{
				code += " obj.style." + chgs[j].attr + "= '" + (chgs[j].from + step*i).toFixed(1) + "'; ";
			}
			
		}
		//document.write(code);
		setTimeout( code, interval * i );
	}
	if(arguments.length > 4){
		setTimeout( following, interval * i );
	}
}

function showMagnifyImage(){
	if(!magnifying){
		
		evolve( "magnify_image", new Array({attr:"width",from:0,to:295}, {attr:"opacity",from:0.2,to:1}), 10, 20, "loadBigImage()");
		magnifying = true;
	}
}

function hideMagnify(){
	$("dragImage").style.display = "none";
	$("waiting_image").style.visibility = "hidden";
	if(magnifying) {
		evolve( "magnify_image", new Array({attr:"width",from:295,to:0}, {attr:"opacity",from:1,to:0.2}), 10, 15);
			magnifying = false;
	}
}


var myimage;
var bigimage_src = "";

function setBigImageSrc(src){
	bigimage_src = src;
}

function loadBigImage(type){
	if(arguments.length < 1){
		var browser=navigator.appName 
		var b_version=navigator.appVersion 
		if(browser=="Microsoft Internet Explorer") 
		{ 
		var version=b_version.split(";"); 
		var trim_Version=version[1].replace(/[ ]/g,""); 
		if(trim_Version=="MSIE6.0")
			void(0);
		} 
		else{	
			$("waiting_image").style.visibility = "visible";
		}
	}
	//alert(bigimage_src);
	myimage = new Image();
	myimage.src = bigimage_src;
	if(myimage.complete){
		$("waiting_image").style.visibility = "hidden";
		$("bImg").src = bigimage_src;
		//$("bigimage_link").href = "javascript: newPopupImage('index.php?l=prd_lg_img&p=" + bigimage_src + "')";
	}
	else{
		myimage.onload = function(){
			$("waiting_image").style.visibility = "hidden";
			$("bImg").src = bigimage_src;
			//$("bigimage_link").href = "javascript: newPopupImage('index.php?l=prd_lg_img&p=" + bigimage_src + "')";
		}
	}
	return false;
}

function createMaskView(mask_id, container_id, cnt_id, cnt_w, cnt_h, cnt_margin){
	px = document.all?"":"px";
	ttl_w = cnt_w+2*cnt_margin;
	ttl_h = cnt_h+2*cnt_margin;
	
	rnt = {};
	rnt.display = "hidden";
	rnt.init = function(){
		$(cnt_id).style.width = cnt_w + px;
		$(cnt_id).style.height = cnt_h + px;
		//$(cnt_id).style.marginLeft =  cnt_margin + px;
		//$(cnt_id).style.marginTop =  cnt_margin + px;
		$(container_id).style.textAlign = "left";
		$(container_id).style.width = (cnt_w + 2*cnt_margin) + px;
		$(container_id).style.height = (cnt_h + 2*cnt_margin) + px;
	}
	
	rnt.show = function(){
		this.relocate();
		this.display = "show";
		
		$(container_id).style.opacity = 0;
		$(container_id).style.filter = "alpha(opacity=0)";
		$(mask_id).style.visibility = "visible";
		$(container_id).style.visibility = "visible";
		$(mask_id).style.display = "block";
		$(container_id).style.display = "block";
		
		evolve(container_id, [{attr: "opacity", from: 0, to: 1}], 50, 5);
		
		that = this;
		callback = function(){
			if( that.display == "hidden" )	return;
			that.relocate();
			setTimeout( callback, 5 );
		}
		callback();
	}
	
	rnt.relocate = function(){
		corner_x = document.documentElement.scrollLeft;
		corner_y = document.documentElement.scrollTop;
		view_w = document.documentElement.clientWidth;
		view_h = document.documentElement.clientHeight;
		if ( /MSIE 6.0/ig.test(navigator.appVersion) ) {
			$(container_id).style.left = corner_x + (view_w - ttl_w)/2 + px;
			$(container_id).style.top = corner_y + (view_h - ttl_h)/2 + px;
		}
		else{
			$(container_id).style.left = (view_w - ttl_w)/2 + px;
			$(container_id).style.top = (view_h - ttl_h)/2 + px;
		}
	}
	
	rnt.hide = function(){
		this.display = "hidden";
		
		$(mask_id).style.visibility = "hidden";
		$(container_id).style.visibility = "hidden";
	}
	
	return rnt;
}


function stopBubble(e){
	eve = e || window.event;
	if(eve.stopPropagation){
		eve.stopPropagation();
	}
	else{
		event.cancelBubble = true;
	}
}

