$(function(){
	//Body Load
	if ((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<="8")) { } else {
		$(".Phuse_PanelContainingDiv td").each(function(){ $(this).css("width",$(this).parent().parent().parent().attr("width")+"px"); });
	}
	$("#clouds").css("height",$(document).height()-400+"px");
	$("#propositions").cycle({fx:"scrollVert",next:"#down",prev:"#up",timeout:10000,after:addLink});
	function addLink(){
		var title = this.title;
		if (title!="null") {
			$("#home_banner").attr("rel",title).css("cursor","pointer");	
		} else {
			$("#home_banner").attr("rel","").css("cursor","default");	
		}
	}
	$(".box1,.box2,.box3,.box4").css({width:"0px",height:"0px",opacity:0});
	$("#blogItems").hide();
	$("#blogFeed").hide().html($("#blogItems").html()).fadeIn();
	$(".capture_form table").each(function(){
		var thisTable = $(this);
		$("tr",thisTable).each(function(){
			$("td:first",this).addClass("label");
			$("td:last",this).addClass("input").children("input").addClass("textbox");
			$("td:last",this).children("label").addClass("checkbox");
		});
		$(".label",thisTable).each(function(){
			var thisLabel = $(this);
			$("span",thisLabel).remove();
			var thisText = thisLabel.text();
			var newText = thisText.replace(/^\s+|\s+$/g, '').replace(":","");
			thisLabel.text(newText);
		}).wrapInner("<div></div>");
		$("input:last",thisTable).addClass("SubmitButton").val("");
		$("textarea",thisTable).parent().addClass("textareaTD");
		$("tr:last",thisTable).addClass("SubmitButtonTR");
		$("td:last",thisTable).addClass("SubmitButtonTD");
	});
    $("#breadcrumb span").each(function(){
        var charReplace = $(this).html();
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        charReplace = charReplace.replace("&gt;","|");
        $(this).html(charReplace);
    });
	if ($.cookie("calculate")) {
		var result = $.cookie("calculate");
		$("#result").html("<p>"+result+"</p>");
		$.cookie("calculate",null);
	}
	$(".tab_link a").removeAttr("target");
	
	//User Interaction
	$("#home_banner").live("click",function(){
		var linkURL = $(this).attr("rel");
		if (linkURL!="") { window.location=linkURL; }
	});
	$(".expand div").live("click",function(){
		$(this).parent().next("div").addClass("active_box").animate({width:"386px",height:"386px",opacity:1},750,"easeOutBack");
	});
	$(".collapse").live("click",function(){
		$(this).parent().removeClass("active_box").animate({width:"0px",height:"0px",opacity:0},750,"easeInBack");
	});
	$("#contact_type div").live("click",function(){
		var thisDiv=$(this).attr("rel");
		$("#contact_form .show_form").hide();
		$("#contact_form #"+thisDiv).fadeIn();
	});
	$("#calculate").live("click",function(){
		var hours = $("#hours").val();
		var rate = $("#rate").val();
		$.cookie("calculate",eval(hours*rate));
		window.location="http://www.i-paye.com/salary-calculator/";
	});
	$(".expand div").live("mouseover",function(){
		var offset = $(this).offset();
		$("#tooltip").css("top",eval(offset.top-40)+"px").css("left",eval(offset.left-78)+"px").fadeIn();
	}).live("mouseout",function(){
		$("#tooltip").fadeOut();
	});
	$("#email").live("click",function(){ window.location="mailto:?subject=i-Paye&body="+window.location; });
	$("#print").live("click",function(){ window.print(); });
});
