function update_gallery_image(image_link, image_id){

	var offset = $("#single_image .content_left img").offset();
	if(offset.top < window.pageYOffset){
		$.scrollTo( '#single_image .content_left img', 800);
	}
	
	$.get("index.php?ajax=1&app=galleries&action=imageInformation",
	{
		image_id: image_id
	}, 	function(data){
		var url_base = "http://images.slatterymedia.com/images/thumbs/450/";
		
		// get handle to element that wraps the image and make it semitransparent 
	    var wrap = $("#single_image .display_image");
	
		var image_height = wrap.children("img").height();
		
		// wrap.fadeTo("normal", 0.5);
		$("#single_image .content_left .image_loading").css("height", parseInt(image_height)+20).show().fadeTo("normal", 0.7); 

	    // the large image from flickr 
	    var img = new Image(); 

	    // call this function after it's loaded 
	    img.onload = function() { 
			
 			wrap.children("img").attr("src", url_base+data["id"]+".jpg");
			image_height = wrap.children("img").height();
			$("#single_image .content_left .image_loading").css("height", parseInt(image_height)+20).fadeTo("slow", 0).hide(0); 
	        // make wrapper fully visible 
	        // wrap.fadeTo("fast", 1); 

	        // change the image 
	    }; 

	    // begin loading the image from flickr 
	    img.src = url_base+data["id"]+".jpg";
	
		var image_description_wrap = $("#single_image .display_image_description");
	
		image_description_wrap.find(".image_collection h3 span.image_round_number").html(data["event_round_number"]);
		image_description_wrap.find(".image_collection h3 span.image_round_name").html(data["event_name"]);
		// Cufon.replace('.replaced_title');
		// Cufon.replace('.replaced_text');
		
		image_description_wrap.find(".image_date").html(data["date"]);
		image_description_wrap.find(".image_id").html("Image ID: "+data["id"]);
		image_description_wrap.find(".image_description").html(data["description"]);
		var link_href = image_description_wrap.find(".image_buy_prints a#btn_buy_print").attr("href");
				
		image_description_wrap.find(".image_buy_prints a#btn_buy_print").attr("href", link_href.replace(/image_id=(\d+)/, "image_id="+data["id"]));
		
		image_description_wrap.find(".image_photographer ul li:first").html(data["Photographer"]);
		
		image_description_wrap.find(".image_features ul").html("");
		image_description_wrap.find(".image_share #image_direct_link").val(image_link);
		image_description_wrap.find(".image_share .fb_link").attr("href", "http://www.facebook.com/share.php?u="+encodeURIComponent(image_link)+"?facebook=1263270986&t="+encodeURIComponent(data["event"]));
		image_description_wrap.find(".image_share .twitter_link").attr("href", "http://twitter.com/home?status="+encodeURIComponent(image_link));
		image_description_wrap.find(".image_share .delicious_link").attr("href", "http://delicious.com/save?v=5&noui&jump=close&url="+encodeURIComponent(image_link)+"&title="+encodeURIComponent(data["event"]));
		
		var slideshow_href = image_description_wrap.find("#btn_slideshow").attr("href");
		image_description_wrap.find("#btn_slideshow").attr("href", slideshow_href.replace(/image_id=(\d+)/, "image_id="+data["id"]));
		
		
		if(data["people"] != undefined){
			
			image_description_wrap.find(".image_description_left").removeClass("hide");
			$.each(data["people"], function(i,item){
	          image_description_wrap.find(".image_features ul").append("<li><a href=\"/galleries/results/?q="+item+"\">"+item+"</a></li>");
	        });
		} else {
			image_description_wrap.find(".image_description_left").addClass("hide");
		}
		
		// analytics
		_gaq.push(['_trackEvent', 'Image', 'View', 'Image ID: '+data["id"]]);
		
	}, "json");
}


function getParameterByName( name, location )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( location );
  if( results == null )
    return "";
  else
    return results[1];
}

function getCollectionPage(page_index){
	if(page_index >=0){
		// var page_items = $("#main_galleries .item .gallery_container").eq(page_index).children().children().children();
		var new_query_string = window.location.search.substring(1).replace(/&page=(\d+)/, "");
		if($("#main_galleries .item .gallery_container").eq(page_index).hasClass("gallery_empty")){
			$("#main_galleries .item .gallery_container").eq(page_index).removeClass("gallery_empty").addClass("gallery_loading");	
			$.get("index.php?ajax=1&app=galleries&action=results&"+new_query_string+"&page="+(page_index+1),
			{}, function(data){					
				$("#main_galleries .item .gallery_container").eq(page_index).append(data);
				$("#main_galleries .item .gallery_container").eq(page_index).removeClass("gallery_loading").addClass("gallery_loaded");
			});
		}
	}
}



function updateItemsInCart(item_index, item_quantity){

	if($("#quantity_"+item_index).val().length > 0 && $("#quantity_"+item_index).val() == parseInt($("#quantity_"+item_index).val())){
			$("#quantity_"+item_index).val(parseInt(item_quantity));
			$(".subtotal").eq(item_index).html((parseInt(item_quantity) * parseFloat($(".unit_price").eq(item_index).html())).toFixed(2));
		
		if($("#quantity_"+item_index).val() > 0){		
			$.get("index.php?ajax=1&app=cart&action=add",
			{
				"image_id": $("#image_id").val(),
				"size": $("#size_"+item_index).val(),
				"quantity": parseInt(item_quantity),
				"paper": $("#paper_"+item_index).val()	
			}, function(data){
				if(data['result'] == "success"){
					$("#add_"+item_index).toggleClass("in_cart", $("#quantity_"+item_index).val()>0)
					if($("#remove_"+item_index).length == 0 && $("#quantity_"+item_index).val() > 0){
						$("#add_"+item_index).before(" <a id=\"remove_"+item_index+"\" class=\"small_buttons remove_item\">-</a> ");
					}
					$("#cart_summary p").html(data['cart_summary']);
				}
			}, "json");
		} else {
			$.get("index.php?ajax=1&app=cart&action=remove",
			{
				"image_id": $("#image_id").val(),
				"size": $("#size_"+item_index).val(),
				"paper": $("#paper_"+item_index).val()	
			}, function(data){
				if(data['result'] == "success"){
					$("#add_"+item_index).removeClass("in_cart");
					$("#remove_"+item_index).remove();
					$("#cart_summary p").html(data['cart_summary']);
				}
			}, "json");
		}
	}
}


function load_image_at(image_div){
	var url_base = "http://images.slatterymedia.com/images/thumbs/800/";
	if($(image_div).length > 0)	{		
		if($(image_div).children().length == 0){
			var current_image_id = $(image_div).attr("id").replace(/^slide_imageid_/, "");
			$('#large_single_image .display_image #slide_imageid_'+current_image_id).append("<img id=\"slide_imageid_"+current_image_id+"\" src=\""+url_base+current_image_id+".jpg\" />");
		};
	};
}

function loadImage(currSlideElement, nextSlideElement, options, forwardFlag){
	load_image_at(currSlideElement);
	load_image_at(nextSlideElement);
	var image_div = $('#large_single_image .display_image div');
	var current_image_div = image_div.index(nextSlideElement);
	load_image_at(image_div.eq(current_image_div+1));
	load_image_at(image_div.eq(current_image_div+2));
	load_image_at(image_div.eq(current_image_div-2));
	load_image_at(image_div.eq(current_image_div-3));
}

function beforeSlideChange(currSlideElement, nextSlideElement, options, forwardFlag){
	loadImage(currSlideElement, nextSlideElement, options, forwardFlag);
}

function afterSlideChange(currSlideElement, nextSlideElement, options, forwardFlag){
	loadImage(currSlideElement, nextSlideElement, options, forwardFlag);	
}

function twitterCallback(twitters) {
  var statusHTML = [];
  for (var i=0; i<twitters.length; i++){
    var username = twitters[i].user.screen_name;
    var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
      return '<a href="'+url+'">'+url+'</a>';
    }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
      return  reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
    });
    statusHTML.push('<li><span>'+status+'</span> <a style="font-size:85%" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id+'">'+relative_time(twitters[i].created_at)+'</a></li>');
  }
  document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function relative_time(time_value) {
  var values = time_value.split(" ");
  time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  var parsed_date = Date.parse(time_value);
  var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  delta = delta + (relative_to.getTimezoneOffset() * 60);

  if (delta < 60) {
    return 'less than a minute ago';
  } else if(delta < 120) {
    return 'about a minute ago';
  } else if(delta < (60*60)) {
    return (parseInt(delta / 60)).toString() + ' minutes ago';
  } else if(delta < (120*60)) {
    return 'about an hour ago';
  } else if(delta < (24*60*60)) {
    return 'about ' + (parseInt(delta / 3600)).toString() + ' hours ago';
  } else if(delta < (48*60*60)) {
    return '1 day ago';
  } else {
    return (parseInt(delta / 86400)).toString() + ' days ago';
  }
}

(function($){ 
	$.fn.glowingEffect = function() { 
		return this.animate({opacity: 0.85}, 500, function(){$(this).animate({opacity: 1}, 500)});
	} 

	$.fn.resizeSlideshow = function(){
		return this.dialog('option', 'position', '[center, top]');
	}
	
	$.fn.prependGallery = function(times) {
		for(var i = 0; i < times; i++){
			this.prepend("<div class=\"item\">\n<div class=\"gallery_container gallery_empty\">\n<div class=\"clear\">\n</div>\n</div>\n</div>");
		}			
		return this;
	}
	$.fn.appendGallery = function(times) {
		for(var i = 0; i < times; i++){
			this.append("<div class=\"item\">\n<div class=\"gallery_container gallery_empty\">\n<div class=\"clear\">\n</div>\n</div>\n</div>");
		}			
		return this;
	}
})(jQuery); 

function useKeyForSlideshow (event) {
	var code = (event.keyCode ? event.keyCode : event.which);
	 if(code == 37) { // right arrow
		$("#slideshow_previous").trigger("click");
		return false;
	 }

	 if(code == 39) { // right arrow
		$("#slideshow_next").trigger("click");
		return false;			
	 }
}

function resizeSlideShow (event){
	$("#slideshow_box").resizeSlideshow();
}

function resizeEnlargeImage (event){
	$("#enlarge_image_box").resizeSlideshow();
}

// change to asynchronous tracking
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2303505-46']);
_gaq.push(['_trackPageview']);


$(document).ready(function(){
	// Cufon.replace('.replaced_title');
	// Cufon.replace('.replaced_text');
	// Cufon.replace('.replaced_with_shadow',{
	// 	textShadow: '1px 1px #3d4753'
	// });
	// Cufon.replace('.replaced_buttons');
	
	// if($('#twitter_section').length > 0){
	// 	$(".twitter_scroll").tweet({
	// 		username: ["aflphotos"],
	// 		count: 1
	//         });
		// .ajaxSuccess(function(e, xhr, settings) {
		// 			$(this).delay(500).scrollable({ 
		// 			    // one configuration property
		// 				vertical: true,
		// 			    size: 1, 
		// 				clickable: false,
		// 				loop: true,
		// 				keyboard: false
		// 			}).circular().autoscroll({interval: 7000, api: true});
		// 			$('#twitter_section').slideDown(300).delay(500).removeClass("hide");
		// });	
	// }
	
	$(".itunes_store_footylite").bind("click", function(){
		// analytics
		_gaq.push(['_trackEvent', 'Footylite', 'Download', "iTunes Store"]);
	});
	
	if($('#slideshow_box').length > 0){
		if(getParameterByName("photostore", window.location.href) == "afl.com.au"){
			$(window).bind("load", function(){
				$('a#btn_slideshow').trigger("click");
			});
		}
	}
	
	if($(".total_page_number").length > 0){
		var gallery_items = $(".items");
	
		var current_page_index = parseInt($(".current_page_number").html());
		var total_page = parseInt($(".total_page_number").html());
	
		if(current_page_index < total_page){
			gallery_items.prependGallery(current_page_index-1).appendGallery(total_page-current_page_index);
		} else {
			current_page_index = total_page;
			gallery_items.prependGallery(current_page_index-1).appendGallery(total_page-current_page_index);
		}
	}
	
	if($(".page").length > 0){
		// Cufon.replace('h1');
		// Cufon.replace('h3');
		// Cufon.replace('h2');		
		// Cufon.replace('h4');
	}
	
	$("#single_image .content_left .image_loading").css("opacity", "0");
	
	setInterval(function(){$("#single_image #btn_buy_print").glowingEffect()}, 1500);
	
	$(".gallery_control li a").removeAttr("href");
	$("a.prevPage").removeAttr("href");
	$("a.nextPage").removeAttr("href");
	
	if($(".home_scrollable").length > 0){
		// return;
		var home_gallery = $(".home_scrollable").scrollable({ 
		    // one configuration property 
		    size: 1, 
			clickable: false,
			loop: true,
			keyboard: false
		}).circular().autoscroll({interval: 7000, api: true});
		
		//.navigator().
		
		var gallery_navi = $(".gallery_control li");
		
		gallery_navi.eq(0).addClass("current");
		
		var gallery_links = new Array("galleries", "galleries/games", "galleries/training", "galleries/media", "galleries/recentPurchase");
		var gallery_title = new Array("Latest Galleries", "Games", "Training", "Media", "Recent Purchases");
		// var gallery_links = new Array("galleries", "galleries/training", "galleries/media", "galleries/popularWeek", "galleries/popularMonth");
		// var gallery_texts = new Array("View More Galleries", "View More Galleries", "View More Galleries", "View Gallery", "View Gallery");
		
		
		home_gallery.onSeek(function(){
			$(".more_galleries a").attr("href", gallery_links[this.getPageIndex()]);
			$(".gallery_heading h2").text(gallery_title[this.getPageIndex()]);
			// Cufon.replace('.gallery_heading h2');
			// $(".more_galleries a").text(gallery_texts[this.getPageIndex()]);
			// Cufon.replace('.more_galleries');
			gallery_navi.removeClass("current");
			gallery_navi.eq(this.getPageIndex()).addClass("current");
		});
		
		gallery_navi.bind("click", function(){
			home_gallery.stop();
			home_gallery.setPage(gallery_navi.index(this));			
			
			setTimeout(function()
			{
				home_gallery.play();
			}, 10000);
			
		});
		
	}
	
	if($(".collection_scrollable").length > 0){
		$(".collection_scrollable").scrollable({ 
		    // one configuration property 
		    size: 1, 
			clickable: false,
			loop: false,
			keyboard: false
		});
	}
	
	if($("#main_galleries .scrollable").length > 0){		
		if($(".item").length < 2){
			$(".nextPage").addClass("disabled");
		}		
		
		var gallery_page = getParameterByName("page", window.location.href);
		
		
		if(gallery_page.length == 0 || parseInt(gallery_page) < 1){
			gallery_page = 1;
		}
		
		if(String(window.location.hash).match(/^#page/)){
			var hash_page  = parseInt(String(window.location.hash).replace("#page",""));
		
			if(hash_page == NaN || hash_page < 1){
				gallery_page = 1;
			} else {
				gallery_page = hash_page;
			}
		}
		
		var main_galleries = $("#main_galleries .scrollable").scrollable({ 
		    // one configuration property
			// api: true,
		    size: 1, 
			clickable: false,
			loop: false,
			keyboard: false
		}).navigator({api: true});
		var image_gallery_name = $('.image_collection .image_round_number').text()+" - " + $('.image_collection .image_round_name').text();
		
		var total_page = parseInt($(".total_page_number").html());
		if(total_page == 1){
			$('.navi').hide();
		}
		
		main_galleries.setPage(parseInt(gallery_page)-1);

		// analytics
		_gaq.push(['_trackEvent', 'Gallery', 'View', image_gallery_name + " - Page "+parseInt(gallery_page)]);
		
		if(gallery_page == 1 && $("#main_galleries .scrollable .items .item").length > 1){
			getCollectionPage(parseInt(gallery_page));
		}
		
		// if(gallery_page > 0){
		// 	getCollectionPage(parseInt(gallery_page)+1);
		// 	getCollectionPage(parseInt(gallery_page)-1);
		// } else {
		// 	getCollectionPage(parseInt(gallery_page)+1);
		// };
		
		// register a callback function 
		main_galleries.onSeek(function() {			
			var get_index  = $("#main_galleries .item").index(this.getVisibleItems());
			// window.location.hash = "page"+(get_index+1);
			getCollectionPage(get_index);
			
			var image_gallery_name = $('.image_collection .image_round_number').text()+" - " + $('.image_collection .image_round_name').text();
			
			// analytics
			_gaq.push(['_trackEvent', 'Gallery', 'View', image_gallery_name + " - Page "+(get_index+1)]);
			$(".current_page_number").html(get_index+1);
			
			if((get_index+1)< this.getPageAmount()){
				getCollectionPage(get_index+1);
			}
			if((get_index-1) >= 0){
				getCollectionPage(get_index-1);
			}			
		});
	}
	
	
	$("#back_in_history").bind("click", function(){
		history.go(-1);
	});
	
	$(".external").attr("target", "_blank"); 
	
	
	// for gallery page with lot of little thumbnails
	$("#main_galleries .image_single_link").live("click", function(){
		var image_id = $(this).attr('id').replace(/^imageid_/, "");
		
		update_gallery_image($(this).attr("href"), image_id);
		return false;		
	});
	

	
	if($('#slideshow_box').length > 0){
		$("a#btn_slideshow").css("display", "block");
		
		$("#slideshow_box").dialog({
			bgiframe: true,
			autoOpen: false,
			width: 800,
			height: 859,
			modal: true,
			resizable: false
		});
		
		$("a#btn_slideshow").live("click",function(){
			$("#slideshow_box").resizeSlideshow().dialog('open');
			$("html").bind("keyup", useKeyForSlideshow);
			$(window).bind("resize", resizeSlideShow);
			return false;
		});
		
		var image_collection;
		var current_image_index;
		var total_images;
		var image_container = $("#slideshow #large_single_image .display_image");
		var image_id;
		var url_base = "http://images.slatterymedia.com/images/thumbs/800/";
		
		$('#slideshow_box').bind('dialogopen', function(event, ui) {
			
			image_id = getParameterByName("image_id", $("a#btn_slideshow").attr("href"));
			
			if(image_container.children().length == 0){
				$.get($("a#btn_slideshow").attr("href"), "", function(data){
					image_collection = data;
					total_images = image_collection.length;
					current_image_index = 0;				
					$.each(image_collection, function(id, item){
						if(item['id'] == image_id){
							image_container.append("<div id=\"slide_imageid_"+item["id"]+"\" class=\"slide_image\"><img src=\""+url_base+item["id"]+".jpg\" /></div>");
							current_image_index = id;
						} else {
							image_container.append("<div id=\"slide_imageid_"+item["id"]+"\" class=\"slide_image\"></div>");
						}

					});
					image_container.cycle({
						"timeout": 7000,
						"prev":   '#slideshow_previous', 
						"next":   '#slideshow_next',
						"startingSlide": current_image_index,
						"containerResize": 0,
						"before": beforeSlideChange,
						"after": afterSlideChange
					});
					image_container.cycle('pause');
					$(".slide_image").eq(current_image_index).find("img").load(function(){
						image_container.cycle('resume');
					});			
				}, "json");
			} else {
				$.each(image_collection, function(id, item){
					if(item['id'] == image_id){
						current_image_index = id;
					}
				});
				
				image_container.cycle({
					"timeout": 7000,
					"prev":   '#slideshow_previous', 
					"next":   '#slideshow_next',
					"startingSlide": current_image_index,
					"containerResize": 0,
					"before": beforeSlideChange,
					"after": afterSlideChange
				});
				
				image_container.cycle('resume');
			}
			return false;
		});
		
		$('#slideshow_box').bind('dialogbeforeclose', function(event, ui) {
			var current_slideshow_image = $("#slideshow #large_single_image .display_image div:visible");
			if(current_slideshow_image.length > 0){
			  	var image_id = current_slideshow_image.attr("id").replace(/^slide_imageid_/, "");
				update_gallery_image(window.location.href.replace(/\&image_id=(\d+)/, "&image_id="+image_id), image_id);
			}
			$(".display_image").cycle('pause');
			$("html").unbind("keyup", useKeyForSlideshow);
			$(window).unbind("resize", resizeSlideShow);
		});
		
		$('.slide_image img').live("click", function(){
			$("#slideshow_box").dialog("close");
			return false;
		});
		
		$('#slideshow_close').live("click", function(){
			$("#slideshow_box").dialog("close");
			return false;
		});

		$('#slideshow_pause').live("click", function() { 
		    image_container.cycle('pause');
			$(this).attr("id", 'slideshow_resume').text("Resume");
			return false;
		});

		$('#slideshow_resume').live("click", function() { 
		    image_container.cycle('resume', true);
			$(this).attr("id", 'slideshow_pause').text("Pause");
			return false;
		});
	};
	
	if($('#enlarge_image_box').length > 0){
		$("#enlarge_image_box").dialog({
			bgiframe: true,
			autoOpen: false,
			width: 800,
			height: 800,
			modal: true,
			resizable: false
		});
		
		var display_image_div = $("#single_image .content_left .display_image");
		
		display_image_div.bind("click", function(){			
			var image_src = $("#single_image .display_image img").attr("src").replace(/\/450\//, "/800/");
			var image_ratio = 800/450;
			var image_width = Math.floor(image_ratio * parseInt(display_image_div.find("img").width()));
			var image_height = Math.floor(image_ratio * parseInt(display_image_div.find("img").height()));
			
			$("#enlarge_image_box .display_image").html("<img src=\""+image_src+"\" />");
			$("#enlarge_image_box").dialog("option", "width", image_width).resizeSlideshow().dialog("option", "height", image_height).dialog('open');
			$(window).bind("resize", resizeEnlargeImage);
			return false;
		});
		
		$("#enlarge_image_box").bind('dialogbeforeclose', function(event, ui) {
			$(window).unbind("resize", resizeEnlargeImage);
		});
		
		$("#enlarge_image_box .display_image").bind("click", function(){
			$("#enlarge_image_box").dialog("close");
		});
		
		$(".ui-widget-overlay").live("click", function(){
			$("#enlarge_image_box").dialog("close");
			$("#slideshow_box").dialog("close");
		});
	}
	
	$(".image_quantity").live("keyup", function(){
		var item_index = $(this).attr('id').replace(/^quantity_/, "");
		updateItemsInCart(item_index, $("#quantity_"+item_index).val());
		return false;
	});
		
	$(".add_item").live("click", function(){
		var item_index = $(this).attr('id').replace(/^add_/, "");
		var item_quantity = 0;
		if($("#quantity_"+item_index).val().length>0 && $("#quantity_"+item_index).val() == parseInt($("#quantity_"+item_index).val())){
			item_quantity = $("#quantity_"+item_index).val();
		}
		updateItemsInCart(item_index, parseInt(item_quantity)+1);
		return false;
	});
	
	$(".remove_item").live("click", function(){
		var item_index = $(this).attr('id').replace(/^remove_/, "");
		
		var item_quantity = 0;
		if($("#quantity_"+item_index).val().length>0 && $("#quantity_"+item_index).val() > 0 && $("#quantity_"+item_index).val() == parseInt($("#quantity_"+item_index).val())){
			item_quantity = $("#quantity_"+item_index).val();
		}
		
		if(parseInt(item_quantity)-1 > 0){
			updateItemsInCart(item_index, parseInt(item_quantity)-1);
		} else {
			updateItemsInCart(item_index, 0);
		}
		
		return false;
	});
	
	var search_term = 'Search team or player name';
	var search_term_player = 'Search players';
	
		$("#searchBoxSubmit").click(function(){
			if ($("#searchBoxQ").val().length < 3 ||$("#searchBoxQ").val() == search_term) {
				$("#search_dialog_box").html("Please ensure your search term is <strong>greater</strong> than 3 characters long.");
				$("#search_dialog_box").dialog({
							bgiframe: true,
							modal: true,
							height: 150,
							minHeight: 150
						}).dialog("open");
				// jAlert("Please ensure your search term is <strong>greater</strong> than 3 characters long.", "Longer Search Term Required");
				return false;
			} else {
				$("#searchBoxForm").submit();
				return false;
			}
		});

		$("#searchPlayerBoxSubmit").click(function(){
			if ($("#searchPlayerBoxQ").val().length < 3 ||$("#searchPlayerBoxQ").val() == 'Search players') {
				$("#search_dialog_box").html("Please ensure your search term is <strong>greater</strong> than 3 characters long.");
				$("#search_dialog_box").dialog({
							bgiframe: true,
							modal: true,
							height: 150,
							minHeight: 150
						}).dialog("open");
				// jAlert("Please ensure your search term is <strong>greater</strong> than 3 characters long.", "Longer Search Term Required");
				return false;
			} else {
				return true;
			}
		});

		$("#searchCloud").click(function(){
			$("#search_cloud").slideToggle('slow');
			if($("#searchCloud").val()=='show search cloud'){
				$("#searchCloud").val('hide search cloud')
			} else {
				$("#searchCloud").val('show search cloud')
			}
		});

		

		
		if($("#searchBoxQ").val() == ""){
			$("#searchBoxQ").val(search_term);	
		}
		
		$("#searchBoxQ").click(function() {
			if ($(this).val() == search_term) {
				$(this).val('');
			}
		});

		// $("#searchPlayerBoxQ").val(search_term_player);
		// $("#searchPlayerBoxQ").click(function() {
		// 	if ($(this).val() == search_term_player) {
		// 		$(this).val('');
		// 	}
		// });
		
		$("#searchBoxQ").bind("blur", function() {
			if ($(this).val() == "") {
				$(this).val(search_term);
			}
		});
		$("#searchPlayerBoxQ").bind("blur", function() {
			if ($(this).val() == "") {
				$(this).val(search_term_player);
			}
		});
		
	if (jQuery.browser.msie){
		/* footer twitter link */
		// $('#twitterlink strong').hide().animate({
		// 	left: '-92px',
		// 	top: '-45px'
		// 	}, 0);
		// 
		// $('#twitterlink').hover(function() {
		// 	$(this).find('strong').stop(true, true).show().animate({
		// 		left: '-92px',
		// 		top: '-55px'
		// 		}, 200);
		// 	}, function() {
		// 	$(this).find('strong').stop(true, true).animate({
		// 		left: '-92px',
		// 		top: '-45px'
		// 		}, 200 ).hide(0);
		// });
		
		$('.product_description_container').hide().animate({
			left: '50px',
			bottom: '70px'
			}, 0).removeClass("hide");
		$('#home_product_description li').hover(function(){
			$(this).find(".product_description_container").stop(true,true).show().animate({
				left: '50px',
				bottom: '80px'
				}, 200);;
		}, function(){
			$(this).find(".product_description_container").stop(true,true).hide().animate({
				left: '50px',
				bottom: '70px'
				}, 200 ).hide(0);
		});
		
		// $('.twitter_container').hide().animate({
		// 	bottom: '20px',
		// 	left: '-10px'
		// 	}, 0).removeClass("hide");
		// $('#twitter_section').hover(function(){
		// 	var twitter_container = $(this).find(".twitter_container");
		// 	if(twitter_container.children().length > 0){
		// 	twitter_container.stop(true,true).show().animate({
		// 		bottom: '30px',
		// 		left: '-10px'
		// 		}, 200);
		// 	}
		// }, function(){
		// 	$(this).find(".twitter_container").stop(true,true).hide().animate({
		// 		bottom: '20px',
		// 		left: '-10px'
		// 		}, 200 ).hide(0);
		// });
		
		
	} else {
		/* footer twitter link */
		// $('#twitterlink strong').hide().animate({
		// 	opacity: '0',
		// 	left: '-92px',
		// 	top: '-45px'
		// 	}, 0);
		// 
		// $('#twitterlink').hover(function() {
		// 	$(this).find('strong').stop(true, true).show().animate({
		// 		opacity: '0.8',
		// 		left: '-92px',
		// 		top: '-55px'
		// 		}, 200);
		// 	}, function() {
		// 	$(this).find('strong').stop(true, true).animate({
		// 		opacity: '0',
		// 		left: '-92px',
		// 		top: '-45px'
		// 		}, 200 ).hide(0);
		// });
		
		$('.product_description_container').hide().animate({
			opacity: '0',
			left: '50px',
			bottom: '70px'
			}, 0).removeClass("hide");
		$('#home_product_description li').hover(function(){
			$(this).find(".product_description_container").stop(true,true).show().animate({
				opacity: '1',
				left: '50px',
				bottom: '80px'
				}, 200);;
		}, function(){
			$(this).find(".product_description_container").stop(true,true).hide().animate({
				opacity: '0',
				left: '50px',
				bottom: '70px'
				}, 200 ).hide(0);
		});
		
		// $('.twitter_container').hide().animate({
		// 	opacity: '0',
		// 	bottom: '20px',
		// 	left: '-10px'
		// 	}, 0).removeClass("hide");
		// $('#twitter_section').hover(function(){
		// 	var twitter_container = $(this).find(".twitter_container");
		// 	if(twitter_container.children().length > 0){
		// 	twitter_container.stop(true,true).show().animate({
		// 		opacity: '1',
		// 		bottom: '30px',
		// 		left: '-10px'
		// 		}, 200);
		// 	}
		// }, function(){
		// 	$(this).find(".twitter_container").stop(true,true).hide().animate({
		// 		opacity: '0',
		// 		bottom: '20px',
		// 		left: '-10px'
		// 		}, 200 ).hide(0);
		// });
	}	

});
