(function($) {
$(function(){

	mainInit();

	$('div.active').makeTabs();

	if ($('#mastad .ad a').length == 0)
	
	if ($('#mastad .ad a, #mastad .ad iframe, #mastad .ad object, #mastad .ad embed').length == 0)
		$('#mastad').remove();
	
	if ($('#mast').length > 0) {
		var bgYPos = $('#mast').position().top-116;
		if ($.browser.msie && $.browser.version<7)
			bgYPos+=2;
		$(document.body).css({backgroundImage:'url(/magazine/graphics/body-bg.jpg)', backgroundPosition:'0 '+bgYPos+'px'});
	}
	if ($('.footer_ad .ad a, .footer_ad .ad iframe, .footer_ad .ad object, .footer_ad .ad embed').length == 0){
		$('#footer').css({backgroundPosition: '0 10px'});
		$('.footer_ad').remove();
	}
	
	// apply PNG fix to the following selectors
	if ($.browser.msie && $.browser.version<7) {
		$.ifixpng.pixel = '/magazine/graphics/pixel.gif';
		$('#logo img[@src$=.png]').ifixpng();
	}

	// focus states on form fields
	$('#columns :text, #columns :password, #columns textarea').css({backgroundColor:'#FFF', color:'#333'})
		.focus(function() {
			$(this).css({backgroundColor:'#FFFFB7', color:'#000', borderColor:'#000'}); })
		.blur(function() { 
			$(this).css({backgroundColor:'#FFF', color:'#333', borderColor:'#BAB9BF'});
	});

	// write out print button for users with JS enabled
	$('.page_options li').removeClass('first');
	$('.page_options ul').prepend('<li class="first"><a href="javascript:window.print()" class="po_print">Print</a></li>');
	$('.page_options_min .po_print').addClass('wvTip').attr('rel','Print');
	$('.paging_results').append('<span class="print"><a href="javascript:window.print()">Print</a></span>');

	// disables buttons
	$('#register .termsandconditions input.button, .myNewsletters .button, #blogPost #comments_form .button, #FreeTrialConfirmForm .button').attr('disabled','disabled').css({cursor:'default', opacity:.5});

	// toggle button style depending on checkbox state
	$('.termsandconditions .formOptions :checkbox, .newsletterformSleeve .formOptions :checkbox, #story #comments_form .note :checkbox, .uploadAgreement :checkbox, #blogPost #comments_form :checkbox, #FreeTrialConfirmForm :checkbox').click(function(){
		if(this.checked) {$('#register .termsandconditions input.button, .myNewsletters .button, #story #comments_form .button, .uploadAgreement .button, #blogPost #comments_form .button, #FreeTrialConfirmForm .button').attr('disabled','').css({cursor:'pointer', opacity:'1'});}
		else {$('#register .termsandconditions input.button, .myNewsletters .button, #story #comments_form .button, .uploadAgreement .button, #blogPost #comments_form .button, #FreeTrialConfirmForm .button').attr('disabled','disabled').css({cursor:'default', opacity:.5});}
	});

	// newsletters box, clear text
	$('#newsletter_block #news_email').focus(function() { if($(this).val() == "Enter email address") $(this).val(''); })
									  .blur(function() { if($(this).val() == "") $(this).val("Enter email address");});
	
	//feedback button
	$('<div class="feedback_close"><a href="#">Close form overlay</a></div>').appendTo('.feedback_box .inner_sleeve');
	$('.feedback_box .feedback_close').click(function(){ $(this).parents('.feedback_box').remove(); return false;});

	// Link form behaviour in footer promo
	$('#promo_container input.button').click(function() {
		var SiteRelocate = $('#siteName option:selected').attr('value');

		if(SiteRelocate != "") {
			window.parent.location.href = SiteRelocate;
		}

		return false;
	});
	function mainInit() {
		$('#mainnav').SetupMenu();
	}
});
})(jQuery);