// set default monthly rate, which may be re-set through Test&Target
var rate = '$17.99';

$(function(){
	$('.popups').easydrag();
});

function launchDemo() {
	window.open('/demo/', 'demo', 'height=390,width=620,scrollbars=no,left=0,top=0,resizable=yes,status=no');
}

function launchDemoEagleEye() {
	window.open('/shipping/eagle-eye/demo/', 'eagle_eye_demo', 'height=576,width=1024,toolbar=no,menubar=no,scrollbars=no,left=0,top=0,resizable=yes,location=no,directories=no,status=no');
}

function startEagleEyeDownload() {
	window.location = '/download/us/cab/stamps/EagleEye.exe';
}

if (typeof(identifier) != 'undefined') {
	if (identifier == 'AdvancedShipping') {
		setCookie('advShip', true, null, '/');
	}
	if (identifier == 'Shipping') {
		setCookie('Shipping', true, null, '/');
	}
	if (identifier == 'Activation') {
		setCookie('Activation', true, null, '/');
	}
}

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function btnCloseNewWindow() {	
	$('.popups div').css('display', 'none');
	$('#popupShadeOut').css('display', 'none');
}

$(document).ready(function() {
	
	$('#btnCalcPO').click(function() {
		window.open('/tools/calculators/postoffice/', 'pocomparison', 'height=302,width=492,scrollbars=no,resizable=yes,status=no');
	});

	$('#calculator, #btnCalcPM').click(function() {
		window.open('/tools/calculators/postagemeter/', 'pmcomparison', 'height=258,width=492,scrollbars=no,resizable=yes,status=no');
	});
	
	$('.btnClose').mousedown(function() {
		var url = $(this).attr('href');
		$('.popups div').css('display', 'none');
		$('#popupShadeOut').css('display', 'none');
		if (url)			
			document.location = url;
	});	

//	$('.btnClose').mousedown(function() {
//		var url = $(this).attr('href');
//		$('.popups div').css('display', 'none');
//		$('#popupShadeOut').css('display', 'none');
//		if (url == '/shipping/eagle-eye/') {
//			window.open(url);
//		} else {
//			document.location = url;
//		}
//	});


	$('#tabs div').mouseout(function () {
		$('#tabs div a').css('color', '#EEE');
	});
	
	$('#tabs div').mouseover(function () {
		if ($(this).css('cursor') != 'auto') {
			$('#tabs div#' + this.id + ' a').css('color', '#FFF');
		}
	});
	
	$('#tabs>div').click(function () {
		if ($(this).css('cursor') != 'auto') {
			if (this.id == 'tabViewDemo') {
				launchDemo();
			} else {
				document.location = $('#' + this.id + ' a').attr('href');
			}
		}
		return false;
	});
	
	$('#btnGetPostage, #headerMenuGetStarted, #goLink, #tabgetStarted, #customTallOfferbox').click(function() {
		if (getCookie('advShip')) {
			window.location = '/advancedshipping/plan-selection/';
		} else if (getCookie('Activation')) {
			window.location = 'http://store.stamps.com/Store/directmail/activation.jsp';
		} else {
			window.location = '/registration/';
		}
		return false;
	});

	$('#offerBox').click(function() {
		if (getCookie('advShip')) {
			window.location = '/advancedshipping/plan-selection/';
		} else if (getCookie('Activation')) {
			window.location = 'http://store.stamps.com/Store/directmail/activation.jsp';
		} else if ('.popupDetails') {
		} else {
			window.location = '/registration/';
		}
		return false;
	});

	$('.btnDetails').click(function() {
		$('.popups div').css('display', 'none');
		switch (this.id) {
			case 'details1':
				$('.popups').css('top', '325px');
				$('.popups').css('width', '334px');
				break;
			case 'details2':
				$('.popups').css('top', '450px');
				$('.popups').css('width', '334px');
				break;
			case 'details3':
				$('.popups').css('top', '570px');
				$('.popups').css('width', '334px');
				break;
			case 'details4':
				$('.popups').css('top', '690px');
				$('.popups').css('width', '487px');
				$('.popups div.mboxDefault').css('display', 'block');
				break;
			case 'details5':
				$('.popups').css('top', '815px');
				$('.popups').css('width', '334px');
				break;
			case 'details6':
				$('.popups').css('top', '930px');
				$('.popups').css('width', '334px');
				break;
		}
		$('.popups div#' + this.id).css('display', 'block');
		$('#popupShadeOut').css('display', 'block');
	});

	$('.popupDetails').click(function() {
		$('.popups div#offerDetails').css('display', 'block');
			$('.popups').css('top', '150px');
			$('.popups').css('left', '350px');
			$('.popups').css('width', '334px');
		$('#popupShadeOut').css('display', 'block');
	});

	equalHeight($('#middleContent>div'));
	
});