/*
                 _   _   _   _   _   _   _   _   _   _   _   _  
                / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ 
               ( X | H | T | M | L | K | I | T | C | H | E | N )
                \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ 
                		coded by www.xhtmlkitchen.com
*/

/*-------------------------------------------------------------------------
=GENERAL FUNCTIONS
-------------------------------------------------------------------------*/		
function isInteger(s) {
	if(s != undefined)
		return (s.toString().search(/^-?[0-9]+$/) == 0);
	else
		return false;
}; 

function calc () {
	var total = 0;
	var tax = 0;
	var total_sum = 0;
	var element = $("div#order_form input");

	for(a=0;a<element.length;a++){
	   if(isInteger(element[a].alt)){
	       if(element[a].checked){
	           total=total+parseInt(element[a].alt);
	       }
	   }
	}
	
	tax = Math.round(total * 18 / 100);
	total_sum = total + tax;
	
	$(".order_sum").text(total +"$");
	$(".tax").text(tax +"$");
	$(".total_sum").text(total_sum +"$");
};

function scrolltotop () {
	$('html, body').animate({scrollTop: 0}, 'fast');
}



/*-------------------------------------------------------------------------
=MAIN PAGE
-------------------------------------------------------------------------*/
$(document).ready(function(){

	$("div#zoom a").mouseover(function(){
		$(this).parent().prev().children("img").css({opacity:"0.65"});
	});
	$("div#zoom a").mouseout(function(){
		$(this).parent().prev().children("img").css({opacity:"1"});
	});
	$("div#zoom a").click(function(){
		$(this).parent().prev().children("img").css({opacity:"1"});
	});
	
	$("div#customer_panel input").click(function(){
		if ($("input#e-mail").val() == "E-Posta") {
			$("div#customer_panel input").val("");
		}
	});
	
	
	
/*-------------------------------------------------------------------------
=PORTFOLIO
-------------------------------------------------------------------------*/		
	$("div.portfolio a").lightBox({
		imageLoading: 'images/lightbox/loading2.gif',
		imageBtnClose: 'images/lightbox/close.gif',
		imageBtnPrev: 'images/lightbox/prev.gif',
		imageBtnNext: 'images/lightbox/next.gif',
		imageBlank: 'images/lightbox/blank.gif',
		txtImage: 'Çalışma:',
		txtOf: '/',
		keyToClose: 'k',
		keyToPrev: 'o',
		keyToNext: 's'
	});
	
	$("a[@rel*=lightbox]").lightBox({
		imageLoading: 'images/lightbox/loading2.gif',
		imageBtnClose: 'images/lightbox/close.gif',
		imageBtnPrev: 'images/lightbox/prev.gif',
		imageBtnNext: 'images/lightbox/next.gif',
		imageBlank: 'images/lightbox/blank.gif',
		txtImage: 'Çalışma:',
		txtOf: '/',
		keyToClose: 'k',
		keyToPrev: 'o',
		keyToNext: 's'
	});  
	
	$("div.portfolio a").mouseover(function(){
		$(this).prev().css({opacity:"0.65"});
	});
	$("div.portfolio a").mouseout(function(){
		$(this).prev().css({opacity:"1"});
	});
	$("div.portfolio a").click(function(){
		$(this).prev().css({opacity:"1"});
	});
});



/*-------------------------------------------------------------------------
=ORDER FORM
-------------------------------------------------------------------------*/		
$("div#order_form").ready(function() {
	var custom_request = 0;
	
	$("div#order_form :radio, div#step2 :checkbox").click(function() {
		$("div#order_form :radio, div#step2 :checkbox").each(function (i) {
			if ($(this).is(":checked")) {
				$(this).parent().addClass("selected");
			}
			else {$(this).parent().removeClass("selected");}
		});
	});	
	
	$("div.web_options input, div.identity_options input").attr("disabled", "true");
	$("div.web_options").css({opacity: "0.4"});
	$("div.identity_options").css({opacity: "0.4"});
		
	$("input#website").click(function() {
		if ($(this).is(":checked")) {
			$("div.web_options").animate({opacity: "1"}, 500);
			$("div.web_options input").removeAttr("disabled");
			$("input#c_request").removeAttr("checked");
		}

		else if ($(this).not(":checked")) {
			$("div.web_options").animate({opacity: "0.4"}, 500);
			$("div.web_options input").attr("disabled", "disabled");
			
			$("div.web_options").find(":radio:checked").removeAttr("checked").parent().removeClass("selected");
		}
		
	});

	$("input#identity").click(function() {
		if ($(this).is(":checked")) {
			$("div.identity_options").animate({opacity: "1"}, 500);
			$("div.identity_options input").removeAttr("disabled");
			$("input#c_request").removeAttr("checked");
		}

		else if ($(this).not(":checked")) {
			$("div.identity_options").animate({opacity: "0.4"}, 500);
			$("div.identity_options input").attr("disabled", "disabled");
			
			$("div.identity_options").find(":radio:checked").removeAttr("checked").parent().removeClass("selected");
		}
	
	});
	
	$("input#c_request").click(function(){
		if($(this).is(":checked")){
			$("input#website, input#identity").removeAttr("checked");	
			$("div.web_options, div.identity_options").animate({opacity: "0.4"}, 500);
			$("div.web_options input, div.identity_options input").attr("disabled", "disabled");
			$("div.web_options, div.identity_options").find(":radio:checked").removeAttr("checked").parent().removeClass("selected");
		}
	});
	
	$("div#step1 button.continue").click(function() {
		if ($("div#step1").css("display") == "block" && $("input#pro").is(":checked") || $("input#semi").is(":checked") || $("input#small").is(":checked") || $("input#template").is(":checked") || $("input#new_identity").is(":checked") || $("input#new_logo").is(":checked") || $("input#c_request").is(":checked")) {
			
			if($("input#pro").is(":checked") || $("input#semi").is(":checked") || $("input#small").is(":checked") || $("input#template").is(":checked")){
				$("div#customize_web").css({display: "block"});
			}
			
			if($("input#new_identity").is(":checked")){
				$("div#customize_identity").css({display: "block"});
			}
			
			if($("input#new_logo").is(":checked")){
				$("div#only_logo").css({display: "block"})
			}
					
			if($("input#c_request").is(":checked")){
				$("div#step1").fadeOut("normal",function() {
					$("div#step3").fadeIn("normal", function(){
						scrolltotop()
					});
				$("li.tab1").removeClass("current_step");
				$("li.tab3").addClass("current_step");
				
				$("div.total").css({display: "none"})
				
				custom_request = 1;
				});
			}	
			else {
				$("div#step1").fadeOut("normal",function() {
					$("div#step2").fadeIn("normal", function(){
						scrolltotop()
					});
				$("li.tab1").removeClass("current_step").next().addClass("current_step");
				custom_request = 0;
				});
			}				
		}
		else {
			alert("Lütfen bir tercih yapın.")
		}
	});
	
	var reset = "div#step2, div#customize_web, div#customize_identity, div#only_logo, div#step3, div#step4";
	
	$("div#step2 button.go_back").click(function(){
			$("div#step2").fadeOut("normal",function() {
				$("div#step1").fadeIn("normal", function(){
					scrolltotop()
				});
			$("li.tab2").removeClass("current_step").prev().addClass("current_step");
			$(reset).css({display: "none"});
			});		
	});
	
	$("div#step2 button.continue").click(function() {
		$("div#step2").fadeOut("normal",function() {
			$("div#step3").fadeIn("normal", function(){
				scrolltotop()
			});
		$("li.tab2").removeClass("current_step").next().addClass("current_step");
		});
	});	
	
	$("div#step3 button.continue").click(function() {
		if ($("input#custom_request_name").val() !== "" || $("input#custom_request_e-mail").val() !== "" || $("textarea#custom_request_comment").val() !== "") {
			$("div#order_summary ul li").remove();
			
			$("div#order_form input:checked").each(function(i){  
				if (isInteger($(this).attr("alt"))) {
					$("div#order_summary ul").append("<li>" + $(this).next().text() + "<strong> (" + $(this).attr("alt") + "$)</strong>" + "</li>");
				}
			});
			
			$("div#order_form input[type=text]").each(function(i){ 
				if ($(this).val().length > 0) {
					$("div#order_summary ul").append("<li>" + $(this).attr("alt") + $(this).val() + "</li>");
				}
			});
			
			$("div#order_form textarea").each(function(i){ 
				if ($(this).val().length > 0) {
					$("div#order_summary ul").append("<li>Taslak İle İlgili Ayrıntılı Açıklamanız: " + $(this).val() + "</li>");
				}
			});
			
			$("div#step3").fadeOut("normal",function() {
				$("div#step4").fadeIn("normal", function(){
					scrolltotop()
				});
			$("li.tab3").removeClass("current_step").next().addClass("current_step");
			});			
		}
		else {alert ("Lütfen doldurulması zorunlu alanları giriniz.");
		}	
	});	
	
	$("div#step3 button.go_back").click(function(){
		if (custom_request == 0) {
			$("div#step3").fadeOut("normal",function() {
				$("div#step2").fadeIn("normal", function(){
					scrolltotop()
				});
			$("li.tab3").removeClass("current_step").prev().addClass("current_step");
			});		
		}
		else {
			$("div#step3").fadeOut("normal",function() {
				$("div#step1").fadeIn("normal", function(){
					scrolltotop()
				});
			$("li.tab3").removeClass("current_step");
			$("li.tab1").addClass("current_step");
			
			$("div.total").css({display: "block"})
			});				
		}
	});
	
	$("div#step4 button.send_order").click(function() {
		if (confirm("Siparişiniz vermek istiyor musunuz?")) {
			alert("Sipariş Verildi...");
		}
		else {return false;}
	});

	$("div#step4 button.go_back").click(function(){
			$("div#step4").fadeOut("normal",function() {
				$("div#step3").fadeIn("normal", function(){
					scrolltotop()
				});
			$("li.tab4").removeClass("current_step").prev().addClass("current_step");
			});		
	});
}); 