﻿var originalFontSize;

$(document).ready(function(){
	$('.harrier h1').sifr({path:'js/font',font:'VAGRounded',color:'#2F4191'});
	$('.box h2').sifr({path:'js/font',font:'VAGRounded',color:'#fff',offsetTop:2});
	$('.box h2.noflash').sifr(false);
	$('.box h2 span').sifr({path:'js/font',font:'VAGRounded',color:'#fff',offsetTop:2});
	$('.noflash .sIFR-replaced embed').css({'float' : 'left', 'position' : 'static'});
	$('.noflash a.feed').css('float','left');
	
	$.externallinks();
	originalFontSize = $('body').css('font-size');
	$(".resetFont").click(function(){
		$.normal();
	});
	$(".increaseFont").click(function(){
		$.big();
		return false;
	});
	$(".decreaseFont").click(function(){
		$.small();
		return false;
	});
	if ($.cookie('fontsize')=='big')
	{
		$.big();
	}
	else if ($.cookie('fontsize')=='small')
	{
		$.small();
	}
	$.firstchildamend();
	$.copyaddress();
	$(".listingsection h2").click(function () {
		$(this).parent().children("ul").toggle();
		if ($(this).parent().children("ul").css('display')=='block')
		{
			$(this).attr('title','click to close');
		}
		else
		{
			$(this).attr('title','click to open');
		}
	});
});

$.small=function(){
	var originalFontSizeNum = parseFloat(originalFontSize, 10);
	var newFontSize = originalFontSizeNum*0.8;
	$('body').css('font-size', newFontSize);
	$(".cart").css('margin-top', "0");
	$.cookie('fontsize', 'small');
}

$.big=function(){
	var originalFontSizeNum = parseFloat(originalFontSize, 10);
	var newFontSize = originalFontSizeNum*1.2;
	$('body').css('font-size', newFontSize);
	$(".cart").css('margin-top', "-5px");
	$.cookie('fontsize', 'big');
}

$.normal=function(){
	$('body').css('font-size', originalFontSize);
	$(".cart").css('margin-top', "0");
	$.cookie('fontsize', 'normal');
}

$.firstchildamend=function(){
	$(".latestreports li:first-child,.upcomingevents li:first-child,.latestnews li:first-child")
	.css("border", "0")
	.css("padding-top", "0")
}

$.copyaddress=function(){
	$('#sameasbilling').click(function(){
		if ($(this).is(":checked")){
			$('#ctl00_middlecontent_checkout21_tbxShippingAddrLine1').val($('#ctl00_middlecontent_checkout21_tbxHBillingAddrLine1').val());
			$('#ctl00_middlecontent_checkout21_tbxShippingAddrLine2').val($('#ctl00_middlecontent_checkout21_tbxHBillingAddrLine2').val());
			$('#ctl00_middlecontent_checkout21_tbxShippingCity').val($('#ctl00_middlecontent_checkout21_tbxHBillingCity').val());
			$('#ctl00_middlecontent_checkout21_tbxShippingState').val($('#ctl00_middlecontent_checkout21_tbxHBillingState').val());
			$('#ctl00_middlecontent_checkout21_tbxShippingPostCode').val($('#ctl00_middlecontent_checkout21_tbxHBillingPostCode').val());
			$("#ctl00_middlecontent_checkout21_dpdShippingCountryList").val($("#ctl00_middlecontent_checkout21_tbxHBillingCountry").val());                    
		}
		else{
			$('#ctl00_middlecontent_checkout21_tbxShippingAddrLine1').val("");
			$('#ctl00_middlecontent_checkout21_tbxShippingAddrLine2').val("");
			$('#ctl00_middlecontent_checkout21_tbxShippingCity').val("");
			$('#ctl00_middlecontent_checkout21_tbxShippingState').val("");
			$('#ctl00_middlecontent_checkout21_tbxShippingPostCode').val("");
			$("#ctl00_middlecontent_checkout21_dpdShippingCountryList").val("");
		}
	});
}

$.externallinks=function(){
	//$('a[!href^="http://www.pharmaceuticalmarkets.com/"]')
	$('a[href^="http://"]')
	.attr({  
		target: "_blank",
		title: function (arr) {
			if ($(this).attr("title").length>0)
			{
				$(this).attr("title",$(this).attr("title") + " (opens in a new window)");
			}
			else
			{
				$(this).attr("title","opens in a new window");
			}
		}
	});
	$('a[href^="http://www.pharmaceuticalmarkets.com/"]')
	.attr({
		target: "_self",
		title: function (arr) {
			$(this).attr("title",$(this).attr("title").replace(/ (opens in a new window)/,""));
			$(this).attr("title",$(this).attr("title").replace(/(opens in a new window)/,""));
		}
	});
}

/*$.sifrh1=function(){
	$('.harrier h1').flash(
		{
			src: 'js/sifr/VAGRounded.swf',
			flashvars: {
				css: [
				'* { color: #2F4191; }',
				'a { color: #0099CC; text-decoration: none; }',
				'a:hover { text-decoration: underline; }'
				].join(' ')
			}
		},
		{ version: 7 },
		function(htmlOptions) {
			htmlOptions.flashvars.txt = this.innerHTML;
			this.innerHTML = '<div>'+this.innerHTML+'</div>';
			var $alt = $(this.firstChild);
			htmlOptions.height = $alt.height();
			htmlOptions.width = $alt.width();
			$alt.addClass('alt');
			$(this)
				.addClass('flash-replaced')
				.prepend($.fn.flash.transform(htmlOptions));
		}
	);
}*/