$(function(){
	jQuery.event.add(window, "load", resizeFrame);
	jQuery.event.add(window, "resize", resizeFrame);
	jQuery.event.add(window, "unload", resizeFrame);
	
	function resizeFrame() 
	{
		var width = $(window).width();
		var height = $(window).height();
		
		var prwidth = $("#pop-request").width();
		var prheight = $("#pop-request").height();
		
		var srwidth = $(".sub-content").width();
		var srheight = $(".sub-content").height();
		
		$("#pop-request").css("left", (width/2) - (prwidth/2) + "px");
		$("#pop-request").css("top", (height/2) - (prheight/2) + "px");
		
		$(".sub-content").css("left", (width/2) - (srwidth/2) + "px");
		$(".sub-content").css("top", (height/2) - (srheight/2) - 50 + "px");
		
		var wrwidth = $(".wrap").width();
		var wrheight = $(".wrap").height();
		$(".wrap").css("left", (width/2) - (wrwidth/2) + "px");
		$(".wrap").css("top", (height/2) - (wrheight/2) - 50 + "px");
	}
	
	$("a").css({
		"cursor": "pointer"
	});
	
	$("input[type='button'], input[type='submit'], input[type='text'], input[type='password'], input[type='reset']").css({
		"overflow": "visible",
		"outline": "none",
		"vertical-align": "middle"
	});
	
	$("input[type='button'], input[type='submit'], input[type='reset']").css({
		"cursor": "pointer"
	});
	
	$(".b-featured .page ul li a[rel=circle]").click(function(){
		$(".b-featured .page ul li a").removeAttr("class");
		$(this).attr("class", "active");
		
		var slide = $(this).attr("slide");
		
		$(".b-featured .content .show").hide();
		$(".b-featured .content .slide"+slide+"").show();
		
		return false;
	});
	
	$(".b-featured .page ul li a[rel=left]").click(function(){
		var act = $(".b-featured .page ul li a[class=active]").attr("slide");
		
		if(act == 1)
		{
			var slide = 5;
		} else {
			var slide = parseInt(act) - 1;
		}
		
		$(".b-featured .page ul li a").removeAttr("class");		
		$(".b-featured .page ul li a[slide="+slide+"]").attr("class", "active");
		
		$(".b-featured .content .show").hide();
		$(".b-featured .content .slide"+slide+"").show();
		
		return false;
	});
	
	$(".b-featured .page ul li a[rel=right]").click(function(){
		var act = $(".b-featured .page ul li a[class=active]").attr("slide");
		
		if(act == 5)
		{
			var slide = 1;
		} else {
			var slide = parseInt(act) + 1;
		}
		
		$(".b-featured .page ul li a").removeAttr("class");		
		$(".b-featured .page ul li a[slide="+slide+"]").attr("class", "active");
		
		$(".b-featured .content .show").hide();
		$(".b-featured .content .slide"+slide+"").show();
		
		return false;
	});
	
	$(".showroom .tab a").click(function(){
		$(".showroom .tab").removeClass("active");
		$(this).parent().addClass("active");
		
		$(".showroom .showbox").hide();
		var showDiv = $(this).attr("rel");
		$("."+showDiv).show();
	});
	
	//size function
	function _change_photo(toheight, towidth)
	{
		$(".showroom .tab").removeClass("active");
		$("a[rel=preview]").parent().addClass("active");
		$(".showroom .showbox").hide();
		$(".preview").show();
		
		var toheight = toheight * 2.54;
		var towidth = towidth * 2.54;
		var toheight = toheight.toFixed(0);
		var towidth = towidth.toFixed(0);
		
		$("div[id='photo']").delay(320).animate({
			left: (318/2)-((towidth)/2) + (10),
			top: (400/2)-((toheight) - 115)
			}, 240, function() {
			//animate complete
		});
		
		$("div[id='photo'] img").delay(320).animate({
			width: towidth,
			height: toheight
			}, 240, function() {
			//animate complete
		});		
	}
	
	function _change_label(width, height)
	{
		$(".widthg strong").html(width+' cm');
		$(".heightg strong").html(height+'<br>cm');
	}
	
	function _change_info(width, height, price)
	{
		$("span[id='height']").html(height);
		$("span[id='width']").html(width);
		$("span[id='cmheight']").html((height * 2.54).toFixed(0));
		$("span[id='cmwidth']").html((width * 2.54).toFixed(0));
		$("span[id='price']").html(price);
		$("input[rel='custom']").attr("value", price);
	}
	
	function _set_wrap()
	{
		$("input[name='setwrap']:checked").each(function () {
        	var wrap = $(this).attr('rel');
			var price = $(this).attr('price');
			var width = $("span[id=width]").html();
			var height = $("span[id=height]").html();
			
			var total = $("span[id=price]").html();
			var totall = parseFloat(total)+parseFloat(price);
			$("span[id=tprice]").html(totall);
			
			var win = width*2.54;
			var win = win.toFixed(0);
			var hin = height*2.54;
			var hin = hin.toFixed(0);
			
			var inside = ' - '+wrap+' Height '+height+' x Width '+width+' inches ('+hin+' x '+win+' cm) |||'+price;
			$("input[name=option1cost]").attr('value', inside);
        });
	}
	
	$("select[name='cheight']").change(function(){
		$("select[name='cheight'] option:selected").each(function () {
        	var str = $(this).attr('rel');
			
			$("select[name='cwidth'] option[rel="+str+"]").attr('selected', 'selected');
			
			var height = $(this).attr('value');
			var width = $("select[name='cwidth'] option[rel="+str+"]").attr('value');
			var price = $("select[name='cwidth'] option[rel="+str+"]").attr('price');
			
			$("input[rel='custom']").attr('checked', 'checked');
			
			_change_info(width, height, price);
			_change_photo(height-((height*32)/100), width-((width*32)/100));
			_change_label(width, height);
			
			_set_wrap();
        });
	});
	
	$("select[name='cwidth']").change(function () {
		$("select[name='cwidth'] option:selected").each(function () {
        	var str = $(this).attr('rel');
			
			$("select[name='cheight'] option[rel="+str+"]").attr('selected', 'selected');
			
			var width = $(this).attr('value');
			var height = $("select[name='cheight'] option[rel="+str+"]").attr('value');
			var price = $("select[name='cheight'] option[rel="+str+"]").attr('price');
			
			$("input[rel='custom']").attr('checked', 'checked');
			
			_change_info(width, height, price);			
			_change_photo(height-((height*32)/100), width-((width*32)/100));
			_change_label(width, height);
			
			_set_wrap();
        });
	});
	
	$("input[rel='custom']").click(function(){
		$("select[name='cwidth'] option[rel=0]").attr('selected', 'selected');
		$("select[name='cheight'] option[rel=0]").attr('selected', 'selected');
		
		var width = $(this).attr('pwidth');
		var height = $(this).attr('pheight');
		_change_label(width, height);
		
		_set_wrap();
	});
	
	$("input[name='setwrap']").click(function(){
		var rel = $(this).attr("rel");
		var price = $(this).attr("price");
			
		$("span[id='option']").html(rel+' + $'+price);
			
		_set_wrap();
	});
	
	$(".size-list input[name='price']").click(function(){
		var height = $(this).attr('pheight');
		var width = $(this).attr('pwidth');
		var price = $(this).attr('pprice');
		
		_change_info(width, height, price);
		_change_photo(height-((height*32)/100), width-((width*32)/100));
		_change_label(width, height);
		
		_set_wrap();
	});
	//size function
	
	$(".b-lastest ul li:nth-child(1n)").css("margin-right", "10px");
	$(".b-lastest ul li:nth-child(2n)").css("margin-right", "0px");
	$(".b-standard > p, #body > p").css("margin-bottom", "15px");
	$("p > strong").css("color", "#333");
	$("p > a.inside, #body > a.inside").css("color", "#0f8dbf");
	$("#body p > strong").css("color", "#333");
	
	$("ul.four-item li:nth-child(1n)").css("margin-right", "10px");
	$("ul.four-item li:nth-child(4n)").css("margin-right", "0px");
	//$("#panel .submit").css("font-size", "1.4em");
	
	
	//input click and return empty
	$("#f_search input[id=keyword], #f_join input[id=a_mail], #f_gallery input[id=gallery], #f_track input[id=email]").click(function(){
		$(this).attr("value", "");
	});
	
	$("#pop-request .close").click(function(){
		$(this).parent().fadeOut("slow");
		$("#pop-request .formResponse").html("");
		document.getElementById("f_request").reset();
	});
	
	$(".open-request").click(function(){
		$("#pop-request").fadeIn("slow");
	});
	
	$(".b-subpanel a").click(function(){
		$("#f_link .formResponse, #f_card .formResponse").html("");
		$(".sub-content").hide().delay(560);
		var showDiv = $(this).attr("rel");
		resizeFrame();
		$("."+showDiv).show();
	});
	
	$(".hide").click(function(){
		$(this).parent().hide();
		$("#f_link .formResponse, #f_card .formResponse").html("");
		resizeFrame();
	});
	
	//Control CSS Style
	$(".l-complete .content ul.char-list li:nth-child(even)").css("background", "#e4e4e4");
	$(".l-complete .content ul.char-list li:nth-child(odd)").css("background", "#f4f4f4");
	//END-Control CSS Style
});
