/**
 * @author: Jonathan Troncoso
 */

function getSlide() {
	var slide = $("#panels").css("left");
	slide = -parseInt(slide)/640;
	return Math.round(slide);
}
function moveSlide(slide) {
	if(slide > ($('#panels').children().size()-1))
	{
		slide = 0;
	}
	else if(slide < 0)
	{
		slide = ($('#panels').children().size()-1);
	}
	var slidePos = -(slide*640) + "px";
	$("#dynamicHeaders div").fadeOut('slow');
	$("#panelHeader" + slide).fadeIn('slow');
	$("#panels").animate(
	{"left": slidePos },
	{
		duration: 1000,
		easing: 'easeInOutExpo'	
	});
}

// non-JQuery Functions
function doClear(theText) {
  if (theText.value == theText.defaultValue) {
      theText.value = "";
  }
}
//Math for estimate
function calcEstimate() {
	
	var general = $("#estimate_general").val();
	var layout = $("input#estimate_layout").val();
	var graphics = $("input#estimate_graphics").val();
  var feel = $("input#estimate_feel").val();
	var estimate = 600;
	

	estimate = estimate + (+$("input#estimate_forum").attr("checked") ? 125 : 0);
	estimate = estimate + (+$("input#estimate_blog").attr("checked") ? 200 : 0);
	estimate = estimate + (+$("input#estimate_cms").attr("checked") ? 50 : 0);
	estimate = estimate + (+$("input#estimate_gallery").attr("checked") ? 125 : 0);
	estimate = estimate + (+$("input#estimate_statistics").attr("checked")? 150 : 0);
	estimate = estimate + (+$("input#estimate_feeds").attr("checked") ? 100 : 0);
	estimate = estimate + (+$("input#estimate_contact").attr("checked") ? 75 : 0);
	estimate = estimate + (+$("input#estimate_search").attr("checked") ? 275 : 0);
	estimate = estimate + (+$("input#estimate_email").attr("checked") ? 50 : 0);
	estimate = estimate + (+$("input#estimate_files").attr("checked") ? 75 : 0);
	estimate = estimate + (+$("input#estimate_seo").attr("checked") ? 150 : 0);
	estimate = estimate + (+$("input#estimate_adsense").attr("checked") ? 150 : 0);
	estimate = estimate + (+$("input#estimate_adwords").attr("checked") ? 150 : 0);
	estimate = estimate + (+$("input#estimate_simple_cart").attr("checked") ? 125 : 0);
	estimate = estimate + (+$("input#estimate_full_cart").attr("checked") ? 325 : 0);
	estimate = estimate + (+$("input#estimate_credit_card").attr("checked") ? 100 : 0);
	
	estimate = estimate * (0.95 + (graphics * 0.0005));
	estimate = estimate * (0.95 + (feel * 0.0005));
	estimate = estimate * (0.9 + (general * 0.0010));
	estimate = estimate * (0.85 + (layout * 0.0015));
	
	if($("#numberVisible").val() != "true"){
		$("#numberVisible").val("true");
		$("#estimate").html('<p id="number"></p><p id="disclaimer">A Free Final Estimate Will Only Be Given When All The Details of the Project Are Understood.<br/> This Quote Only Serves to Give a Rough “Ball-Park” Figure. Actual Quote May Vary Considerably</p>');
  }
	$("#number").html("$"+Math.ceil(estimate));
}
	
//Animation Bindings
$("#middle").click(function(){
	var slide = $('#panels').children().size();
});
$("#left").click(function(){
	var slide = getSlide();
	moveSlide(slide-1);
	return false;
});
$("#right").click(function(){
	var slide = getSlide();
	moveSlide(slide+1);
	return false;
});

$(function() {
	//Scrolling Links
	$(".quoteButton").click(function(){
		$('html, body').animate({
			scrollTop: $("#quoteMenu").offset().top
		}, {
			easing: 'easeInOutExpo',
			duration: 500
		});
		return false;
	});
	
	$(".homeButton").click(function(){
		$('html, body').animate({
			scrollTop: 0
		}, {
			easing: 'easeInOutExpo',
			duration: 500
		});
		return false;
	});
	$(".contactButton").click(function(){
		$('html, body').animate({
			scrollTop: $(document).height() - $(window).height()
		}, {
			easing: 'easeInOutExpo',
			duration: 500
		});
		return false;
	});
	
	//Printer Button
	// var oldButton = jQuery("#printer");
	//   var newButton = oldButton.clone();
	//   newButton.attr("type", "button");
	//   newButton.attr("id", "newPrinter");
	//   newButton.insertBefore(oldButton);
	//   oldButton.remove();
	//   newButton.attr("id", "printer");
	// newButton
	$("#printer").click(function(){
		var estimate_general = $("#estimate_general").val();
		var estimate_layout = $("#estimate_layout").val();
		var estimate_graphics = $("#estimate_graphics").val();
	  var estimate_feel = $("#estimate_feel").val();
		var returnVar = false;
		
		if (estimate_general == "") {
      $("#estimate_general_error").show();
			estimate_general =0;
      returnVar = true;
    }else{
	    $("#estimate_general_error").hide();
		}
		
		if (estimate_layout == "") {
      $("#estimate_layout_error").show();
      returnVar = true;
			estimate_layout=0;
    }else{
	    $("#estimate_layout_error").hide();
		}
		
		if (estimate_graphics == "") {
      $("#estimate_graphics_error").show();
      returnVar = true;
			estimate_graphics=0;
    }else{
		   $("#estimate_graphics_error").hide();
		}
		
		if (estimate_feel == "") {
      $("#estimate_feel_error").show();
      returnVar = true;
			estimate_feel=0;
    }else{
	    $("#estimate_feel_error").hide();
		}
		
		if(returnVar == true) {
			return false;
		}
		$("#printerForm").submit();
	});

	
	$("#mailButton").unbind('click').click(function(){
    $("#letter").animate(
			{"top": "43px"},
			{
				duration: 1000,
				easing: 'easeOutBounce'	
		});
     $('#contact_estimate_general').val($('#estimate_general').val());
     $('#contact_estimate_layout').val($('#estimate_layout').val());
     $('#contact_estimate_graphics').val($('#estimate_graphics').val());
     $('#contact_estimate_feel').val($('#estimate_feel').val());
     $('#contact_estimate_content').val($('#estimate_content').val());
     $('#contact_estimate_forum').val($('#estimate_forum').attr('checked'));
     $('#contact_estimate_blog').val($('#estimate_blog').attr('checked'));
     $('#contact_estimate_cms').val($('#estimate_cms').attr('checked'));
     $('#contact_estimate_gallery').val($('#estimate_gallery').attr('checked'));
     $('#contact_estimate_statistics').val($('#estimate_statistics').attr('checked'));
     $('#contact_estimate_feeds').val($('#estimate_feeds').attr('checked'));
     $('#contact_estimate_contact').val($('#estimate_contact').attr('checked'));
     $('#contact_estimate_search').val($('#estimate_search').attr('checked'));
     $('#contact_estimate_email').val($('#estimate_email').attr('checked'));
     $('#contact_estimate_files').val($('#estimate_files').attr('checked'));
     $('#contact_estimate_seo').val($('#estimate_seo').attr('checked'));
     $('#contact_estimate_adsense').val($('#estimate_adsense').attr('checked'));
     $('#contact_estimate_adwords').val($('#estimate_adwords').attr('checked'));
     $('#contact_estimate_simple_cart').val($('#estimate_simple_cart').attr('checked'));
     $('#contact_estimate_full_cart').val($('#estimate_full_cart').attr('checked'));
     $('#contact_estimate_credit_card').val($('#estimate_credit_card').attr('checked'));
	});
	// $.extend($.fx.step,{
	//     backgroundPosition: function(fx) {
	//             if (fx.state === 0 && typeof fx.end == 'string') {
	//                 var start = $.curCSS(fx.elem,'backgroundPosition');
	//                 start = toArray(start);
	//                 fx.start = [start[0],start[2]];
	//                 var end = toArray(fx.end);
	//                 fx.end = [end[0],end[2]];
	//                 fx.unit = [end[1],end[3]];
	// 		}
	//             var nowPosX = [];
	//             nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
	//             nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
	//             fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
	// 
	//            function toArray(strg){
	//                strg = strg.replace(/left|top/g,'0px');
	//                strg = strg.replace(/right|bottom/g,'100%');
	//                strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
	//                var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
	//                return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	//            }
	//         }
	// });
	
	
	//Q&A Arrays
//*	
	var general = new Array();
	general[1] = "I already have a site. It just needs some improvement.";
	general[2] = "I need a simple website that doesn't need user-interaction.";
	general[3] = "I need a simple blogging site.";
	general[4] = "I need a comprehensive site from scratch.";
	
	var layout = new Array();
	layout[1] = "I will be providing graphics and an HTML template";
	layout[2] = "I have no idea. You design it";
	layout[3] = "I have an overall idea of what I want, but design it how you believe will be best";
	layout[4] = "You will be designing the web site from sketches/graphics I provide";
	layout[5] = "I have a strong idea of what I want. You'll have to follow my directions to the letter";
	
	var graphics = new Array();
	graphics[1] = "I will be providing all graphics";
	graphics[2] = "I need some graphics made";
	graphics[3] = "I need some stock photographs acquired";
	graphics[4] = "I need a professional to take custom photographs";

	var feel = new Array();
	feel[1] = "I don't need any animation";
	feel[2] = "I'd like some minimalistic transitions to improve the feel of my site";
	feel[3] = "I'd like heavy effects/transitions/animations to make my site really come alive";
	feel[4] = "I want flash in my site Do I need flash?";
	
	// Shit to do
	
	$("#accordion").accordion({ header: "h3" });
	$("#accordion div div ul li input").bind('click', function(){
		calcEstimate();
	})
	$("#contentAmount").html('<span class="question">Where will the content come from?</span');
	$("#radio1").buttonset();
	
	$(".selector").bind('click', function(event, ui) {
		switch($("input[@name='radio']:checked").val())
		{
		case '0':
			$("#contentAmount").html("I can add content myself using a Content Management System");
		  break;
		case '1':
			$("#contentAmount").html("I can email you the content in a Word document. The price will depend on the number of pages");
		  break;
		case '2':
			$("#contentAmount").html("You can take content from my existing site");
		}
	});
	$("#extraFeatures").hide();
	$("#estimate_general").hide();
	$("#estimate_layout").hide();
	$("#estimate_graphics").hide();
	$("#estimate_feel").hide();

	$("#generalSlider").slider({
		range: "min",
		animate:true,
		min: 0,
		max: 400,
		value: 100,
		slide: function(event, ui) {
			for(var i in general){ if ((ui.value/100) <= i){
				$("#estimate_general").val(ui.value);
				$("#generalAmount").html(general[i]);
				break;
			}}
			
		calcEstimate();
		}
	});
	$("#layoutSlider").slider({
		range: "min",
		animate:true,
		min: 0,
		max: 400,
		value: 100,
		slide: function(event, ui) {
			for(var i in layout){ if ((ui.value/100) <= i){
					$("#estimate_layout").val(ui.value);
					$("#layoutAmount").html(layout[i]);
					break;
			}}

		calcEstimate();
		}
	});
	$("#graphicsSlider").slider({
		range: "min",
		animate:true,
		min: 0,
		max: 400,
		value: 100,
		slide: function(event, ui) {
			for(var i in graphics){ if ((ui.value/100) <= i){
					$("#graphicsAmount").html(graphics[i]);
					$("#estimate_graphics").val(ui.value);
					break;
			}}

		calcEstimate();
		}
	});
	$("#feelSlider").slider({
		range: "min",
		animate:true,
		min: 0,
		max: 400,
		value: 100,
		slide: function(event, ui) {
			for(var i in feel){ if ((ui.value/100) <= i){
					$("#feelAmount").html(feel[i]);
					$("#estimate_feel").val(ui.value);
					break;
			}}

		calcEstimate();
		}
	});
	
	
	$("#feelAmount").html('<span class="question">How important is the feel of the site?</span>');
	$("#layoutAmount").html('<span class="question">How will I go about designing your site?</span>');
	$("#graphicsAmount").html('<span class="question">Where shall I get the graphics for this site from?</span>');
	$("#generalAmount").html('<span class="question">How can I help you?</span>');
	//359
//*/

});
	
	
	//361
	// 
	// $("#fuzzies").animate(
	// 	{backgroundPosition:"(0 100000)"}, 
	// 	{duration:10000000}
	// 	);
// });

