var timer;
	$(document).ready(function() {

	// ================================================================================================
	// $(".price-table-cell a[title]").tooltip();
	tooltip();

	if (document.domain == "www.myletterfromsanta.co.uk"){
		$(document).snowfall();
		$('body').snowfall({
			flakeCount : 75,		// number
			flakeColor : '#ddd', // string
			flakeIndex: 999999,		// number
			minSize : 2,			// number
			maxSize : 4,			// number
			minSpeed : 2,			// number
			maxSpeed : 3			// number
		});
	}
	
	getSearch();
		
	var defaults = {
		directory: 'turn',      // The directory we're in
		side: 'right',          // change me to "right" if you want rightness
		turnImage: 'fold-sw.png',  // The triangle-shaped fold image
		maxHeight: 400,         // The maximum height. Duh.
		startingWidth: 80,      // The height and width 
		startingHeight: 80,     // with which to start (these should probably be camelCase, d'oh.)
		autoCurl: true         // If this is set to true, the fold will curl/uncurl on mouseover/mouseout.
	};

// $('#peel-target').fold(defaults);
// $('#peel-target').toggle();

	// ================================================================================================
	// Activate thumbnail viewer if there is one
	jQuery.noConflict();
	$(".shots").yoxview({
			backgroundColor: 'Black',
			playDelay: 5000
	});

	// ================================================================================================
	// Activate TABS if there are any
	// Simple Tab code from : http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/
	//When page loads…
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//attribute an idea to each of the top tabs so we can manipulate them later
	//it is using the href value you enter, in this case #tab1, #tab2 etc and adds _top
	$('.tabs li').each(function(i) {
		var thisId = $(this).find("a").attr("href");
		thisId = thisId.substring(1,thisId.length) + '_top';
		$(this).attr("id",thisId);
	});
	
	function changeTab(activeTab){
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(activeTab + '_top').addClass("active"); //Add "active" class to selected tab, using the id created at document load	
		$(".tab_content").hide(); //Hide all tab content
		$(activeTab).fadeIn(); //Fade in the active content
	}

	//check to see if a tab is called onload
	if (location.hash!=""){changeTab(location.hash);}//if you call the page and want to show a tab other than the first, for instance index.html#tab4

	//On Click Event
	$("ul.tabs li").click(function() {
		//call above function
		changeTab($(this).find("a").attr("href"));
		return false;
	});

	//if you want to open a tab from a link which is not a tab, make sure you give that link a class of external_link
	//example: Lets go to tab 4 to contact us
	//this can be within your content anywhere on the page, remember that it will not jump to the menu!
	$(".external_link").click(function() {
		//call above function
		changeTab($(this).attr("href"));
		return false;
	});

	// ================================================================================================
	// manage availability of options on product detail page!
	$('#artwork_source_design').click(function() {	
		if( $(this).is(':checked') ){

			$('#artwork_check').attr('checked', false);
			$('#artwork_check').attr('disabled', 'disabled');

			$('#artwork_crops').attr('checked', false);
			$('#artwork_crops').attr('disabled', 'disabled');

			$('#artwork_source_upload').attr('checked', false);
			$('#artwork_source_upload').attr('disabled', 'disabled');

			$('#artwork_source_email').attr('checked', false);
			$('#artwork_source_email').attr('disabled', 'disabled');

			$('#artwork_source_template').attr('checked', false);
			$('#artwork_source_template').attr('disabled', 'disabled');
						
		} else {
			$('#artwork_check').removeAttr('disabled');
			$('#artwork_crops').removeAttr('disabled');
			$('#artwork_source_upload').removeAttr('disabled');
			$('#artwork_source_email').removeAttr('disabled');			
			$('#artwork_source_template').removeAttr('disabled');			
		}
	});
	
	$('#artwork_source_upload').click(function() {	
		if( $(this).is(':checked') ){
			$('#artwork_source_email').attr('checked', false);
			$('#artwork_source_email').attr('disabled', 'disabled');
			$('#artwork_source_design').attr('checked', false);
			$('#artwork_source_design').attr('disabled', 'disabled');		
			$('#artwork_source_template').attr('checked', false);			
			$('#artwork_source_template').attr('disabled', 'disabled');
		} else {
			if( !$('#artwork_source_upload').is(':checked') && !$('#artwork_crops').is(':checked') && !$('#artwork_check').is(':checked')) {
				$('#artwork_source_email').removeAttr('disabled');							
				$('#artwork_source_design').removeAttr('disabled');
				$('#artwork_source_template').removeAttr('disabled');
			}
		}
	});
	
	$('#artwork_source_email').click(function() {	
		if( $(this).is(':checked') ){
			$('#artwork_source_upload').attr('checked', false);
			$('#artwork_source_upload').attr('disabled', 'disabled');
			$('#artwork_source_design').attr('checked', false);
			$('#artwork_source_design').attr('disabled', 'disabled');		
			$('#artwork_source_template').attr('checked', false);			
			$('#artwork_source_template').attr('disabled', 'disabled');
		} else {
			if( !$('#artwork_source_email').is(':checked') && !$('#artwork_crops').is(':checked') && !$('#artwork_check').is(':checked')) {
				$('#artwork_source_upload').removeAttr('disabled');							
				$('#artwork_source_design').removeAttr('disabled');
				$('#artwork_source_template').removeAttr('disabled');
			}
		}
	});
	
	$('#artwork_crops').click(function() {	
		if( $(this).is(':checked') ){
			$('#artwork_source_design').attr('checked', false);
			$('#artwork_source_design').attr('disabled', 'disabled');					
			$('#artwork_source_template').attr('checked', false);			
			$('#artwork_source_template').attr('disabled', 'disabled');
			
		} else {
			if( !$('#artwork_source_upload').is(':checked') && !$('#artwork_crops').is(':checked') && !$('#artwork_check').is(':checked')){
				$('#artwork_source_design').removeAttr('disabled');
				$('#artwork_source_template').removeAttr('disabled');
			}

		}
	});	
	$('#artwork_check').click(function() {	
		if( $(this).is(':checked') ){
			$('#artwork_source_design').attr('checked', false);
			$('#artwork_source_design').attr('disabled', 'disabled');			
			$('#artwork_source_template').attr('checked', false);			
			$('#artwork_source_template').attr('disabled', 'disabled');
			
		} else {
			if( !$('#artwork_source_upload').is(':checked') && !$('#artwork_crops').is(':checked') && !$('#artwork_check').is(':checked')){
				$('#artwork_source_design').removeAttr('disabled');
				$('#artwork_source_template').removeAttr('disabled');
			}

		}
	});		
	$('#artwork_source_template').click(function() {	
		if( $(this).is(':checked') ){
			$('#artwork_source_design').attr('checked', false);
			$('#artwork_source_design').attr('disabled', 'disabled');						

			$('#artwork_check').attr('checked', false);
			$('#artwork_check').attr('disabled', 'disabled');

			$('#artwork_crops').attr('checked', false);
			$('#artwork_crops').attr('disabled', 'disabled');

			$('#artwork_source_upload').attr('checked', false);
			$('#artwork_source_upload').attr('disabled', 'disabled');

		} else {

			if( !$('#artwork_source_upload').is(':checked') && !$('#artwork_crops').is(':checked') && !$('#artwork_check').is(':checked')){
				$('#artwork_source_design').removeAttr('disabled');
				$('#artwork_check').removeAttr('disabled');
				$('#artwork_crops').removeAttr('disabled');
				$('#artwork_source_upload').removeAttr('disabled');				
			}
		}
	});		
	
	function TemplateSelected(){
		$('#artwork_source_template').attr('checked', true);		
		
		$('#artwork_source_design').attr('checked', false);
		$('#artwork_source_design').attr('disabled', 'disabled');						

		$('#artwork_check').attr('checked', false);
		$('#artwork_check').attr('disabled', 'disabled');

		$('#artwork_crops').attr('checked', false);
		$('#artwork_crops').attr('disabled', 'disabled');

		$('#artwork_source_upload').attr('checked', false);
		$('#artwork_source_upload').attr('disabled', 'disabled');		
	}
	
	$('.template').click(function() {	
		TemplateSelected();
	});			

	// ================================================================================================
	
	$("#coupon").click(function() {
		if ($(this).val()=="enter your voucher code here"){
			$(this).val("");
		}
	});

	// ================================================================================================
	
	$("#activate_code").click(function() {
		if ($(this).val()=="enter your code here"){
			$(this).val("");
		}
	});	

	// ================================================================================================
	$(".reseller-video-link").click(function(event) {
		var detail = ".reseller-video";
			//Get the screen height and width
			var maskHeight = $(document).height();
			var maskWidth = $(window).width();
			//Set height and width to mask to fill up the whole screen
			$('#modal').css({'width':'100%','height':maskHeight});		
			//transition effect    
			$('#modal').fadeIn(100);   
			//Get the window height and width
			var winH = $(window).height();
			var winW = $(window).width()-20;					 
			//Set the popup window to center
			$(detail).css('top',  $(window).scrollTop()+100);				
			$(detail).css('left', winW/2-$(detail).width()/2);	
			//transition effect
			$(detail).fadeIn(100); 

	});	

	$(".close_btn").click(function(event) {	
		var dd = ".reseller-video";
		var detail = dd.replace("close", "detail");
		$("#modal").fadeOut(500); //Hide background...		
		$(detail).fadeOut(0); //Hide box...
	});

	// ================================================================================================
	// Banner form functionality
	// ================================================================================================
	function conversion(id) {
		inches2 = (($(id).val()) * 39.370078740157477);
		res_feet = parseInt(inches2 / 12);
		res_inches = Math.round((inches2 % 12)*100)/100;
		$(id+"_fi").html(res_feet+" feet, "+res_inches+" inches");
	}	
	
	function banner_price() {
		cost = $("#banner_cost").val();
		width = $("#banner_width").val();
		height = $("#banner_height").val();		
		qty = $("#banner_qty").val();				
		total = (width * height) * cost;
		total = total.toFixed(2) * qty;
		if (total < cost) total = cost;
		$("#banner_price").html("&pound;"+total.toFixed(2));
	}
	
	$("#banner_height").blur(function() {
		value = $(this).val(); 
		bh = parseFloat(value.replace(/[^0-9.]/g,""));
		bh = bh.toFixed(2)		
		$(this).val(bh);
		if ($(this).val()=="") $(this).val("1.00");
		if ($(this).val()<0.5) $(this).val("0.50");
		if ($(this).val()>1.45) $(this).val("1.45");
		conversion("#banner_height");
		banner_price();
	});

	$("#banner_width").blur(function() {
		value = $(this).val(); 
		bw = parseFloat(value.replace(/[^0-9.]/g,""));
		bw = bw.toFixed(2)
		$(this).val(bw);
		if ($(this).val()=="") $(this).val("1.00");
		if ($(this).val()<1.0) $(this).val("1.00");
		if ($(this).val()>10.00) $(this).val("10.00");
		conversion("#banner_width");
		banner_price();
	});

	$("#banner_qty").blur(function() {
		value = $(this).val(); 
		q = parseFloat(value.replace(/[^0-9]/g,""));
		$(this).val(q);
		if ($(this).val()=="") $(this).val("1");
		banner_price();
	});

	$(".gallery-img-template").click(function(event) {	
		value = event.target.id
		this_id = parseFloat(value.replace(/[^0-9.]/g,""));
		$('#sel'+this_id).attr('checked', true);		
		TemplateSelected();
	});

});

$(window).load(function() {

	// ================================================================================================
	// Activate fader if there is one
	$('#slider').nivoSlider({
			effect:'boxRain', //Specify sets like: 'fold,fade,sliceDown'
			slices:8,
			animSpeed:500, //Slide transition speed
			pauseTime:4000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:false, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:false, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:false, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){}, //Triggers after all slides have been shown
			lastSlide: function(){}, //Triggers when last slide is shown
			afterLoad: function(){} //Triggers when slider has loaded
	});

	// ================================================================================================
	// Upload form - show png message during upload.
	$('#fileupload').click(function() {	
		if (/AppleWebKit/.test(navigator.userAgent)) {
			closeKeepAlive();
			document.forms["detail"].submit();
			$('#PopUp').css('left', 0);			
		} else {
			closeKeepAlive();
			document.forms["detail"].submit();
			$('#PopUp').css('left', 0);
		}
	});

	// ================================================================================================
	// Review form - handle stars and hidden fields
	
});

function getSearch()
{
	clearTimeout(timer);
	var results="";
	var i=0;

	$.post("/GetTwitter.php", {query: ""},  function(xml){
																									 
		$('entry',xml).each(function(i){
		var title = $(this).find('content').text();
		i=i+1;
		$("#twitter-"+i).html(title);
	});
	
});

timer = setTimeout('getSearch()', 600000);
}




/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -5;
		yOffset = 8;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
