jQuery(document).ready(function($){
	var timer = 0;
	var i_pos = undefined;

	var current_hash = window.location.hash;

	$("a[rel^='prettyPhoto']").prettyPhoto({showTitle: true, theme: 'dark_rounded'});

	if(current_hash != "")	{
		var hash_trigger = $(current_hash + '-launch');
		if(hash_trigger.length)	{
			hash_trigger.click();
		}
	}

	$(".diagram-showcase").bind("mouseenter",function(){
		$(this).find(".diagram-container").css("border-color","#c4c4c4");
		i_pos = $(".actual-diagram").css("background-position");

		timer = setTimeout(function(){
			$(".actual-diagram").stop().animate(
				{
					//backgroundPosition: '50% 50%',
					height: '670px'
				}, 400,	"easeOutQuad"
			);
			$(".zoom-preview").stop().animate(
				{
					right: '-55px'
				}, 200,	"easeOutQuad"
			);
		}, 250);
	}).bind("mouseleave",function(){
		$(this).find(".diagram-container").css("border-color","#e2e2e2");

		clearTimeout(timer);
		$(".actual-diagram").stop().animate(
			{
				//backgroundPosition: i_pos,
				height: '135px'
			}, 400,	"easeOutQuad"
		);
		$(".zoom-preview").stop().animate(
			{
				right: '16px'
			}, 450, "easeOutQuad"
		);
	});


	// We should use this code in homepage too

	$('.cta-demos-bg').css("opacity","0");

	$('.cta-demos-link').bind("mouseenter",function(){
		this_cta = $(this).parent().parent();
		if (this_cta.find('.cta-demos-bg').css('opacity') < 1)	{
			if ($(this).hasClass('cta-demos-webmail'))	{
				this_cta.find('.cta-demos-bg').css('backgroundPosition','0% 100%');
				this_cta.find('.cta-demos-bg').stop().animate(
					{opacity: "1"},
					{duration:200}
				);
			}
			else if	($(this).hasClass('cta-demos-webadmin'))	{
				this_cta.find('.cta-demos-bg').css('backgroundPosition','50% 100%');
				this_cta.find('.cta-demos-bg').stop().animate(
					{opacity: "1"},
					{duration:200}
				);
			}
			else	{
				this_cta.find('.cta-demos-bg').css('backgroundPosition','100% 100%');
				this_cta.find('.cta-demos-bg').stop().animate(
					{opacity: "1"},
					{duration:200}
				);
			}
		}
		else	{
			if ($(this).hasClass('cta-demos-webmail'))	{
				this_cta.find('.cta-demos-bg').stop().animate(
					{backgroundPosition:'0% 100%'},
					{duration:300},
					"easein"
				);
			}
			else if	($(this).hasClass('cta-demos-webadmin'))	{
				this_cta.find('.cta-demos-bg').stop().animate(
					{backgroundPosition:'50% 100%'},
					{duration:300},
					"easein"
				);
			}
			else	{
				this_cta.find('.cta-demos-bg').stop().animate(
					{backgroundPosition:'100% 100%'},
					{duration:300},
					"easein"
				);
			}
		}
	});

	$('.cta-demos-links').bind("mouseleave",function(){
		$('.cta-demos-bg').stop().animate(
			{opacity: "0"},
			{duration:200}
		);
	});

	// clear the hover on simple CTA bars (ex. partners)
	$('.cta-demos-description').bind("mouseenter",function(){
		$('.cta-demos-bg').stop().animate(
			{opacity: "0"},
			{duration:200}
		);
	});


	// Old Code Below

	$(".icon-fade-feat").bind("mouseenter",function(){
		timer = setTimeout(function(){
			$(".icon-fade").not(".icon-fade-feat").animate({
				opacity: 0.4
			}, 200);
		}, 200);
	}).bind("mouseleave",function(){
		clearTimeout(timer);
		$(".icon-fade").not(".icon-fade-feat").animate({
			opacity: 1
		}, 200);
	});

	$(".icon-fade-buy").bind("mouseenter",function(){
		timer = setTimeout(function(){
			$(".icon-fade").not(".icon-fade-buy").animate({
				opacity: 0.4
			}, 200);
		}, 200);
	}).bind("mouseleave",function(){
		clearTimeout(timer);
		$(".icon-fade").not(".icon-fade-buy").animate({
			opacity: 1
		}, 200);
	});

	$(".icon-fade-stop").bind("mouseenter",function(){
		timer = setTimeout(function(){
			$(".icon-fade").not(".icon-fade-stop").animate({
				opacity: 0.4
			}, 200);
		}, 200);
	}).bind("mouseleave",function(){
		clearTimeout(timer);
		$(".icon-fade").not(".icon-fade-stop").animate({
			opacity: 1
		}, 200);
	});


	empty_str = "";
	default_str = "Your Domain Name";
	error_message = "Please Enter Your Domain"

	$("#domainsearch_input").click(function(){
		$(this).removeClass("hostway-buy-error");
		if (jQuery.trim($(this).attr("value")) == default_str || jQuery.trim($(this).attr("value")) == error_message)
			$(this).attr("value",empty_str);
	});

	$("#domainsearch_input").blur(function(){
		if (jQuery.trim($(this).attr("value")) == empty_str)
			$(this).attr("value",default_str);
	});

	$("#hostway-buy-home").submit(function(event){
		input_box_value = jQuery.trim($("#domainsearch_input").attr("value"));
		empty_str = "";
		default_str = "Your Domain Name";
		error_message = "Please Enter Your Domain"
		
		if (input_box_value == empty_str || input_box_value == default_str || input_box_value == error_message)	{
			$("#domainsearch_input").addClass("hostway-buy-error");
			$("#domainsearch_input").attr("value",error_message);
			event.preventDefault();
		}
	});

})
