var postaddress = '<a href="mailto:&#103;&#101;&#116;&#115;&#116;&#97;&#114;&#116;&#101;&#100;&#64;&#97;&#103;&#101;&#110;&#116;&#118;&#105;&#100;&#101;&#111;&#112;&#114;&#111;&#46;&#99;&#111;&#109;?subject=I want to get started with Agent Video Pro" title="Get started with Agent Video Pro">&#103;&#101;&#116;&#115;&#116;&#97;&#114;&#116;&#101;&#100; |@| &#97;&#103;&#101;&#110;&#116;&#118;&#105;&#100;&#101;&#111;&#112;&#114;&#111; |.| &#99;&#111;&#109;</a>'

//Stop CSS Background Flickering in Internet Explorer 6
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

var blank = new Image();
blank.src = '/images/image.gif';

function fixPng(png) {
	// get src
	var src = png.src;
	// set width and height
	if (!png.style.width) { png.style.width = $(png).width(); }
	if (!png.style.height) { png.style.height = $(png).height(); }
	// replace by blank image
	png.onload = function() { };
	png.src = blank.src;
	// set filter (display original image)
	png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

//function to get random number from 1 to n (maxVal)
function randomToN(maxVal,floatVal) {
   var randVal = Math.random()*maxVal;
   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
}

/*
 * @return Array Return an array with page width, height and window width, height
 */
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}


// JQUERY READY
$(document).ready(function() {

//$("#output").show();

$('#postal').html(postaddress);

$('#ValidHTML5').html('<img src="/images/valid_html5.gif" alt="valid_html5" width="80" height="15" />');



$('.external').attr("target","_blank");

$('#lab, #birdie, .core-item').click(function() {
	var link = $(this).find('a').attr('href');
	document.location.href = link;
});

$('.core-item').hover(
	function () {
		$(this).addClass('over');
	},
	function () {
		$(this).removeClass('over');
	}
);

$('#moreWeb').click(function() {
	$('.section2').toggle();
});

$('#btn-getstarted a').hover(
	function () {
		$(this).addClass('over');
	},
	function () {
		$(this).removeClass('over');
	}
);

$('#moreWeb').toggle(
	function () {
		$('.section2').show("slow");
		$(this).html('<span>&ndash;</span>LESS');
	},
	function () {
		$('.section2').hide("fast");
		$(this).html('<span>+</span>MORE');
	}
);

var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
if (badBrowser) {
	// get all pngs on page
	$('img[src$=.png]').each(function() {
		if (!this.complete) {
			this.onload = function() { fixPng(this) };
		} else {
			fixPng(this);
		}
	});
}


//$('#GetStartedForm').validate({
//  rules: {
//    firstname: {
//      required: true,
//      minlength: 2
//    },
//    lastname: {
//      required: true,
//      minlength: 2
//    },
//    email: {
//      required: true,
//      email: true
//    },
//    phone: {
//      required: true,
//      minlength: 7
//    },
//    company: {
//      required: true,
//      minlength: 2
//    },
//    agent_count: {
//      required: true,
//      minlength: 1
//    }
//  }
//});


// Only for page error
if ($('#errorMsg').length > 0) {
	$.doTimeout(10000, function(){
		$('#errorMsg').slideUp("slow");
	});
}


function tryOutAVP() {
	$('body').prepend('<div id="sampleWin" class="draggable"></div>');
	$('body').prepend('<div id="avp_agent_1" class="sample PM__WatchBtn">hhh</div>');;
	$('html, body').animate({scrollTop:0}, 'fast');
	//$('#avp_agent_1').html('<div id="avp_agent_1" class="sample PM__WatchBtn">'+hhh+'</div>').show();
	var rawURL = $("input#urlstring").val();
	if (rawURL.indexOf("http://") !== -1 || rawURL.indexOf("https://") !== -1) {
		var theURL = rawURL;
	}
	else {
		var theURL = "http://"+rawURL;
	}	
	var seeAVP = '<iframe src="'+theURL+'" id="pageURL" marginwidth="0" marginheight="0" width=100%" height="100%" frameborder="0"></iframe>'+
	'<div class="fullCover"></div>'+
	'<div id="coverTitleBar"><h1><span class="note">Drag the video preview area below to another position to simulate it on your site. Click the play button to open the video player.</span>Agent Video Pro Module Preview</h1><div id="closePreview">[CLOSE]</div></div>';
	$('body').append(seeAVP);
	$('html').css('overflow','hidden');
	$('.fullCover').css('height',arrayPageSize[1]).show();
	$('#avp_agent_1').clone(true).appendTo('#sampleWin');
	$('#sampleWin h5').html('Watch My Video Profile');
	$('#sampleWin').draggable();
	$('#closePreview').click(function() {
		$('#pageURL, .fullCover, #coverTitleBar, #sampleWin').hide().remove();
		$('html').css('overflow','auto');
		try {
			PM_exitPresModule();
		}
		catch (err) {
		}
	});
	return false;
}

$('#seeAVP').validate({
  rules: {
    urlstring: {
    	required: true,
    	url: true
    }
  },
 submitHandler: function(form) {
   tryOutAVP();
 }
});

getPageSize();
}); // JQUERY END
