/* Author: 

*/

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

$(document).ready(function(){
	if( $(".videoslist a").length !== 0 ) {
		$(".videoslist a").click(function() {
			$.fancybox({
					'padding'		: 0,
					'autoScale'		: false,
					'transitionIn'	: 'none',
					'transitionOut'	: 'none',
					'title'			: this.title,
					'width'			: 680,
					'height'		: 495,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
						 'wmode'		: 'transparent',
						'allowfullscreen'	: 'true'
					}
				});
		
			return false;
		});
	}
	if( $('#main').lenght != 0 ) {
		$('#main').waypoint(function(event, direction) {
			$('.top').toggleClass('hidden', direction === "up");
		}, {
			offset: '-100%'
		}).find('#glossary-menu').waypoint(function(event, direction) {
			$(this).parent().toggleClass('sticky', direction === "down");
			event.stopPropagation();
		}); 
	}
	$('.cartbutton').live('click', function(){
		$(this).parents('form:eq(0)').submit();
		return false;
	});
	
	if( $(".checkoutbutton").length != 0 ) {
		$(".checkoutbutton").colorbox({
			width	:	"350px", 
			inline	:	true, 
			href	:	"#countrywarning"
		});
	}
	if( $('.checkoutpaybutton').length != 0 ) {
		$('.checkoutpaybutton').live('click', function(){
			$('form').submit();
			return false;
		});
	}
	if( $('select[name=jumpMenu]').length != 0 ) {
		$('select[name=jumpMenu]').change(function(){
			var ob = $(this);
			var selected = $(':selected', ob).text();
			
			var uk = $('input[name=uk-delivery-cost]').val();
			var none_uk = $('input[name=none-uk-delivery-cost]').val();
			var curDel = $('.delVal');
			var curTot = $('.totVal');
			var tot = $('input[name=default]').val();
			if( selected !== 'United Kingdom' ) {
				curDel.html('&pound;' + none_uk);
				curTot.html('&pound;' + (Number(tot)+Number(none_uk)));
			}else{
				curDel.html('&pound;' + uk);
				curTot.html('&pound;' + (Number(tot)+Number(uk)));
			}			
		});
	}
	if( $('input[name=sbbutton]').length != 0 ) {
		$('form').submit();
	}
})
























