$(document).ready(function(){
	$('#postcode').keyup(function(){
		var postcode = $('#postcode').val().toUpperCase();
		$('#postcode').val(postcode)
	});

});
var um;
function determineRegion(obj, dd, pc) {
    if(obj.value == 'GB') {
        document.getElementById(dd).disabled = false;
		document.getElementById(pc).className = 'required postcode';
    } else {
        document.getElementById(dd).disabled = true;
		document.getElementById(pc).className = 'required';
    }
}
$(document).ready(function(){
	
	$(document).everyTime(60000, function(i) {
  		$.post("/template/keepalive.php",'',function(response){
		});
	}, 0);

	$('#slideshow').cycle({
		fx: 'fade'
	});
	var height = $(window).width() * (729/1920);
	$('#slideshow').css('height',height);
	
	$(window).resize(function() {
		var height = $(window).width() * (729/1920);
		$('#slideshow').css('height',height);
	});
	
	$('#print-large').click(function() {
		var loc = '/image-printable/?img=' + $('.main-image').attr('href');
		window.open(loc, '_blank'); return false;
	});

	$('#mailinglist').fancybox({
		href: "/mailinglist.php",
		type: 'iframe',
		modal:true,
		width:350,
		height:400
	});
	
	 $(".eventLink").fancybox({
         'width' : 700,
         'height' : 500,
         'autoScale' : false,
         'transitionIn' : 'none',
         'transitionOut' : 'none',
         'type' : 'iframe'
     });
	 
	 $(".latestNews").fancybox({
         'width' : 700,
         'height' : 500,
         'autoScale' : false,
         'transitionIn' : 'none',
         'transitionOut' : 'none',
         'type' : 'iframe'
     });
	
	jQuery('#special-items-car').jcarousel({
		wrap:'circular',
		auto:6,
		animation:'slow'
	});
	

	var scrollerWidth = 0;
	$("#corporate-scroller #inner a img").each(function(i){
		scrollerWidth += ($(this).width()+10);
	});


	var scrollerInner = $("#corporate-scroller #inner");

	var scrollerContent = scrollerInner.html();

	scrollerInner.append(scrollerContent);

	scroller(scrollerInner,scrollerWidth);

	$("#corporate-scroller").hover(function(){
		scrollerInner.pauseAnimation();
	},function(){
		scrollerInner.resumeAnimation();
	});
	
	$("#catsearch").keyup(function(){
		
		var input = $("#catsearch");
		
		if(input.val()) {
			
			if($('.extra_options').length) {  
			} else {
				
				var extra_options = "<option class=\"extra_options\" selected=\"selected\" value=\"MOST_RELEVANT\">Most Relevant First</option>"
				extra_options += "<option class=\"extra_options\" value=\"LEAST_RELEVANT\">Least Relevant First</option>";
				$('#sort').append(extra_options);
				if($('.null_search_opt').length) um = true;
				$('.null_search_opt').remove();
			}
		} else {
			$('.extra_options').remove();
			if(um == true) {
				var extra_options = "<option class=\"null_search_opt\" selected=\"selected\" value=\"NEWEST_ADDED\">Most Recently Added</option>"
				extra_options += "<option class=\"null_search_opt\" value=\"OLDEST_ADDED\">Least Recently Added</option>";
				$('#sort').append(extra_options);
			}
		}
	});

	
});

function scroller(obj,width){
	obj.startAnimation({
		marginLeft:-width
	},50000,"linear",function(){
		obj.css("marginLeft","0px");
		scroller(obj,width);
	});

}
