$(document).ready(function() {
		
		$(document).pngFix(); 
		
		
		$('#pause').click(function() { 
			$('#slides').cycle('pause'); 
			return false; 
		});
		
		$('#play').click(function() { 
			$('#slides').cycle('resume'); 
			return false;
		});
		
		$('#controls').hide();
		$('#slideshow').hover(
		    function() {
		        $('#controls').fadeIn();
		    },
		    function() { 
		        $('#controls').hide(); 
		    }
		);

		
		// alexph - 27/05/2010
		// Remove first slide image, but ignoring the homepage
		if(window.location.pathname != '/') {
			$('div#slides li:first').remove();
			
			//hide pagination if only one li
			if( $('div#slides li').length <= 1 )
			{
				$('ul#slides_pagination').hide();
				
				$('#slideshow').unbind('hover');
				$('#controls').remove();
			}
		}
		
		$('#slides').cycle({
			fx: 'scrollLeft',
			speed: 400,
			timeout: 0,
			next: '#next',
			prev: '#prev',
			pager: '#slides_pagination', 
			pagerAnchorBuilder: function(idx, slide) { 
				return '<li><a href="#"><span>' + (idx + 1) + '</span></a></li>'; 
			}
		});
		
	
		
		$('#myhasbean ul.mainlist li:first').hover(function () {
			$('#myhasbean ul.extras').slideDown(300);
		}, function () {
		});
		
		$('#myhasbean').hover(function () {
		}, function () {
			$('#myhasbean ul.extras').slideUp(300);
		});
		
	
	
		$('input#search_query, input#nl_first_name, input#nl_email').each(function () {
			var initial = $(this).val();
			$(this).focus(function () {
				if ($(this).val() === initial) {
					$(this).val('');
				}
			}).blur(function () {
				if ($(this).val() === '') {
					$(this).val(initial);
				}
			});
		});
		
		$('a[href*="http://www.coffee101.co.uk"], a[href*="http://www.flickr.com/photos/hasbean"], a[href*="http://www.hasblog.co.uk"], [href*="http://www.inmymug.com"], a[href*="http://www.twitter.com/hasbean"]').attr('target', '_blank');
	
		// TOP PANEL
		// Expand Panel
		$("#open").click(function(){
			$("div#panel").slideDown("fast");
	
		});	
	
		// Collapse Panel
		$("#close").click(function(){
			$("div#panel").slideUp("fast");	
		});		
	
		// Switch buttons from "Log In | Register" to "Close Panel" on click
		$("#toggle a").click(function () {
			$("#toggle a").toggle();
		});		
		
	
	
		// COMPARE HOVER
		//the hover callback handles mouseover and mouseout in one event
		$('.compare-hover').hover(function () {
			$(this).find('.ProductCompareButton').fadeIn('fast').addClass('focused');
		}, function () {
			// mouse out
		
			//we see if we can find a checkbox that is 'checked' within this LI.
			//only hide the compare box if one DOESN'T exist
			if(!$(this).find('.ProductCompareButton input:checkbox').attr('checked'))
				$(this).find('.ProductCompareButton').hide();
		
			//this has the effect of leaving a selected compare checkbox visible
			//to the user
		});
		
	
		
		// MENU DROP
		if(document.all) {
			$('#Menu li.HasSubMenu').hover(function() {
				$(this).addClass('over');
				return false;
			},
			function() {
				$(this).removeClass('over');
			});
		}
		
	
		
		//Video player 
		//Dummy controls trigger the dynamic insertion of Video tag
		$('#play-dummy').live("click", function() {
			$('#video-dummy').trigger("click");
			return false;
		});
		
		$('#video-dummy').live("click", function(){
			$('#videoholder').children().remove();
			
			$('#videoholder').html('<video id="footer_video" class="video-js" width="414" height="250" controls="controls" preload="auto" poster="/video/images/inmymug.jpg"><source id="footer_video_mp4" type=\'video/mp4; codecs="avc1.42E01E, mp4a.40.2"\' src="http://hasbean.tv/video/IMM/IMM-124.mp4" /><source id="footer_video_webm" type=\'video/webm; codecs="vp8, vorbis"\' src="http://hasbean.tv/video/IMM/IMM-124.webm" /><source id="footer_video_ogv" type=\'video/ogg; codecs="theora, vorbis"\' src="http://hasbean.tv/video/IMM/IMM-124.ogv" /><!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><object id="flash_fallback_1" class="vjs-flash-fallback" width="414" height="250" type="application/x-shockwave-flash" 	       data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value=\'config={"playlist":["/video/images/inmymug.jpg", {"url": "http://www.hasbean.co.uk/video/current/imm.flv","autoPlay":false,"autoBuffering":false}]}\' /><!-- Image Fallback. Typically the same as the poster image. --><img src="/video/images/inmymug.jpg" width="414" height="250" alt="Poster Image" title="No video playback capabilities." /></object></video>');
			
			VideoJS.DOMReady(function(){
		      // Using the video's ID or element
		      var myPlayer = VideoJS.setup("footer_video");
		      myPlayer.play(); // Starts playing the video for this player.
		    });
			
			
		});
	
	
		//Breadcrumb 
		$("#PageBreadcrumb").jBreadCrumb({timeExpansionAnimation: '100', timeCompressionAnimation: '100', timeInitialCollapse: '100'});
		
			if($(".hbCoffeeElement").attr("id") !== undefined)
			{
				//alert($(".hbCoffeeElement").attr("id"));

				$("table").insertAfter('.hbCoffeeElement').addClass('hbCoffeeElementFilled');

				$('.hbCoffeeElementFilled').load("/spreadsheet/output.php?bean_id="+$(".hbCoffeeElement").attr("id"));

				$(".hbCoffeeElement").remove();
			}
		
		
		
		//More HasBean
		
		//var marginTopDefault = parseInt($("#more_hasbean_new").css("margin-top"));
		var h = "352px"
		
		$("#open").live("click", function(){
			
			//$("#more_hasbean_new").animate({ 'margin-top': "0" }, 'slow');
			 $("#more_hasbean").animate({ 'height': h }, 'slow');
		});
		
		$('#close').live("click", function() {
				//$("#more_hasbean_new").animate({ 'margin-top': marginTopDefault }, 'slow');
				$("#more_hasbean").animate({ 'height': "0px" }, 'slow');
		});
});
