function jqPngFix() {
    try {
        //ie6 png transperency fix
        $.each($("img[src$=.png],img[src$=.PNG]"), function () {
            var img = $(this);
            img.css({"width": img.width(),"height": img.height(), "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.attr("src") + "', sizingMethod='scale')"});
            img.attr("src","images/construct/blank.gif");
        });
    } catch(e) {
        alert(e.description)
    }
}
function launchTC() {
	$('#termsLink').trigger('click');
}


$(document).ready(function(){
	if (document.getElementById("bookmarkLink")) {
		var bookBut = document.getElementById("bookmarkLink");
		bookBut.onclick=function() {
			if (document.all) {
				bookmarkurl=document.location;
				bookmarktitle="Animates website";
				window.external.AddFavorite(bookmarkurl,bookmarktitle);
			} else {
				alert("Unfortunately your browser doesn't support adding bookmarks via this link.\n\nTo bookmark this page please use your browser's menu.");
			}
			return false;
		}
	}
	
	if ($.browser.msie && $.browser.version == '6.0') {
		jqPngFix();
	}
	$('.stockists input[type="text"]').fadeTo('fast',0.5);
	$('#postcode').keydown(function(event) {
		if (event.keyCode == '13') {
			event.preventDefault();
			$('p.cta.submit a').trigger('click');
		}
	});
	$('.stockists label').hide();
	$('.stockists input[type="text"]').each(function() {
		$(this).attr('value',$(this).prev().html());
	});
	$('.stockists input[type="text"]').bind({
		focus: function() {
			$(this).fadeTo('fast',1);
			if ($(this).attr("value") == $(this).prev().html()) {
				$(this).attr("value","");
			}
		},
		blur: function() {
			$(this).fadeTo('fast',0.5);
			if (!$(this).attr("value")) {
				$(this).attr("value",$(this).prev().html());
			}
		}
	});
	$('.stockists input[type="text"]').change(function() {
		var pcArray = $(this).attr('value').split(' ');
		$(this).attr('value', pcArray[0]);
	});
	
	$('input[type="submit"]').each(function() {
		$(this).replaceWith('<p class="cta submit"><a href="#">'+$(this).attr('value')+'</a></p>');
	});
	
	
	$('p.cta.submit a').click(function() {
		newURL = $(this).parents('form').attr('action');
		newURL += '?postcode='+$('#postcode').val();
		newURL += '&title='+$('#title').val();
		newURL += '&showothers='+$('#showothers').val();
		$(this).attr('href',newURL);
		//$(this).parents('form').submit();
		//return false;
	});
	$('p.cta.submit a').fancybox({
		'width'				: 800,
		'height'			: '75%',
        'autoScale'     	: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000',
		'showNavArrows'		: false
	});
	$('.footer a[rel="popup"]').fancybox({
		'width'				: 600,
		'height'			: '75%',
        'autoScale'     	: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000',
		'showNavArrows'		: false
	});
	$('.footer a[rel="popupSmall"]').fancybox({
		'width'				: 600,
		'height'			: 250,
        'autoScale'     	: false,
		'type'				: 'iframe',
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000',
		'showNavArrows'		: false
	});
	
	$('.selector li').css( { "bottom": "-180px" } ).hover(function() {
		$(this).css( { "z-index": 10 } );
		$(this).animate( { "bottom": "-130px" } );
	}, function() {
		$(this).css( { "z-index": 1 } );
		$(this).animate( { "bottom": "-180px" } );
	});
	
});
