// JavaScript Document
var i = 0;
var referred = false;

$j(document).ready(function(){	
	$j("#productSubNav a").click(function(){
		getPage($j(this));
		return false;
	});
	$j("#banner ul a[href=try-it]").click(function(){
		getPage($j("#productSubNav a[title=Try It]"));
		return false;
	});
	//if(window.location.href.indexOf("express") != -1) $j("#banner ul").css("display", "none");
});

function getPage($lmnt){
	if(!$lmnt.is("a")) $lmnt = $j("#productSubNav a[title=Overview]");
	
	$j("#subContent").html('<div style="text-align:center;"><img src="/assets/js/loadingAnimation.gif" width="208" height="13" /></div>');
	
	$j("#productSubNav li.active").removeClass("active");
	$lmnt.parent().addClass("active");
	
	$j.get($lmnt.attr("href"), function(data){
		$j("#subContent").html(data);
		initAJAX();
	});
}

function initAJAX(){
	//create and connect feature animation
	$j("#featureMenu a").click(function(){
		var newPos = parseInt($j(this).attr("rel")) * -720;
		$j("#featureMenu a.active").removeClass("active");
		$j(this).addClass("active");
		$j("#features").stop().animate({top: newPos+"px"}, 700);
		
		return false;
	});
	
	tb_init('#subContent a.thickbox, #subContent area.thickbox, #subContent input.thickbox');
	//$j("#subContent input:checkbox, #subContent input:radio").addClass("styled");
	
	$j(".productTour").click(function(){
		launchTour();
		return false;
	});
	
	$j("#tryitBtn").click(function(){
		var valid = true;
		var json = {};
		
		$j(".required").each(function(){
			if($j(this).val() == ""){
				$j(this).css("border-color", "#FF0000");
				$j(this).parent().append("<span class=\"formValidationError\">This is a required field.</span>");
				valid = false;
			}
		});
		$j("#tryItForm input[type=text]").each(function(){
			json[$j(this).attr("name")] = $j(this).val();
		});
		$j("#tryItForm input[type=checkbox]").each(function(){
			json[$j(this).attr("name")] = $j(this).attr("checked");
		});
		$j("#tryItForm select").each(function(){
			json[$j(this).attr("name")] = $j(this).val();
		});
		json["sendingForm"] = $j("input[name=sendingForm]").val();
		
		if(valid){
			$j(this).css("display", "none");
			$j.post($j("#tryItForm form").attr("action"), json, function(data){
				if(data == "success"){
					$j("#tryItForm").html("<h1>Thank You...</h1><p>for your interest in MediaShout Version 4!</p><h1>&nbsp;</h1><p>We have received your request for a free 45 day full-featured evaluation of MediaShout.  You will receive an email shortly with a link to download the latest MediaShout Evaluation Version.</p>										  <div style='display:inline;'><img height='1' width='1' style='border-style:none;' alt='' src='http://www.googleadservices.com/pagead/conversion/1037272745/?label=F1fhCL_hnwEQqY3O7gM&amp;guid=ON&amp;script=0'/></div>");
				}else{
					alert("There was an error while submitting your information:  "+data);
					$j("#tryitBtn").css("display", "block");
				}
			});
		}
		return false;
	});
	
	$j("#subContent select").addClass("dropdown");
	
	$j("#subContent input:text").addClass("textbox");
	$j(".textbox").focus(function(){
		$j(this).css("border-color", "#72A6B4");
	});
	$j(".textbox").blur(function(){
		$j(this).css("border-color", "#CACACA");
	});
	Custom.init();
}