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

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return 0;
}

$(document).ready(function() {
	
	/* ie6 test and notification */  
	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	var cookieIE6 = getCookie('steve_irwin_ie6');
	
	if(isIE6 == true && cookieIE6!=1){

		$("#content").prepend("<div id='ie6'><p>We have detected that you are using the web browser Internet Explorer 6<br />For the best experience with this web site please consider upgrading your browser.</p></div> ");
		// remember, these are the possible parameters for Set_Cookie:
		// name, value, expires, path, domain, secure
		setCookie('steve_irwin_ie6',1,365);
		//alert("ie6 detected");
	}

/* navigation drop down - all pages*/
	$.getScript("/jscripts/superfish.js", function(){
		jQuery('ul.sf-menu').superfish();
	});
	
	// remove bottom border of last list item in sub menu
	if ( $("#content_submenu").length > 0 ) {
			$("#content_submenu > li:last").css("border-bottom","none");
	}

	if ( $("#khaki_it_video").length > 0 ) {
		$.getScript("/jscripts/jquery.flash.js", function(){
			$("#khaki_it_video a").css("visible","none");
			var mysrc = $("#khaki_it_video a").attr('href');
			$("#khaki_it_video").flash(
				{
					width: 290, 
					height: 178,
					wmode: 'transparent',  
					src: mysrc
				},
        		{ version: 8 }
			);
		});
	}
	
	if ( $("#competition_video").length > 0 ) {
		$.getScript("/jscripts/jquery.flash.js", function(){
			$("#competition_video a").css("visible","none");
			var mysrc = $("#competition_video a").attr('href');
			$("#competition_video").flash(
				{
					width: 725, 
					height: 401,
					wmode: 'transparent',  
					src: mysrc
				},
        		{ version: 8 }
			);
		});
	}	
	

	/* twitter container - only where div id="juitterContainer" */
	if ( $("#juitterContainer").length > 0 ) {
		//var tabContainers = $('#tabs > div');
		//tabContainers.hide().filter(':first').show();
		$('#tabs #firsttab').show();
		
		$.getScript("/jscripts/jquery.juitter.js", function(){
			$.Juitter.start({
				searchType:"fromUser", // needed, you can use "searchWord", "fromUser", "toUser"
				searchObject:"steveirwinday", // needed, you can insert a username here or a word to be searched for, if you wish multiple search, separate the words by comma.
		
				// The values below will overwrite the ones on the Juitter default configuration. 
				// They are optional here.
				// I'm changing here as a example only
				lang:"en", // restricts the search by the given language
				live:"live-60", // the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates.
				placeHolder:"juitterContainer", // Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
				loadMSG: "Loading messages...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on 
				imgName: "loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
				total: 5, // number of tweets to be show - max 100
				readMore: "Read it on Twitter", // read more message to be show after the tweet content
				nameUser:"image", // insert "image" to show avatar of "text" to show the name of the user that sent the tweet 
				filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"
				
			});	
			

			$("#tabs #firsttab a").click(function(){
				$('#tabs ul.tabNavigation a').removeClass('firsttab_selected secondtab_selected thirdtab_selected');
				$(this).addClass('firsttab_selected');
				
				$.Juitter.start({
					searchType:"searchWord",
					searchObject:"steveirwinday",
					live:"live-60", // it will be updated every 120 seconds/2 minutes
					filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"
				});
			});
			$("#tabs #secondtab a").click(function(){
				$('#tabs ul.tabNavigation a').removeClass('firsttab_selected secondtab_selected thirdtab_selected');
				$(this).addClass('secondtab_selected');
				
				$.Juitter.start({
					searchType:"searchWord",
					searchObject:"australiazoo",
					live:"live-60",  // it will be update every 20 seconds 
					filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"

				});
			});
			$("#tabs #thirdtab a").click(function(){
				$('#tabs ul.tabNavigation a').removeClass('firsttab_selected secondtab_selected thirdtab_selected');
				$(this).addClass('thirdtab_selected');
												  
				$.Juitter.start({
					searchType:"fromUser",
					searchObject:"wildwarriors",
					live:"live-60", // it will be updated every 180 seconds/3 minutes
					filter:"sex->*BAD word*,porn->*BAD word*,fuck->*BAD word*,shit->*BAD word*"
				});
			});
			
		});		
	}
	
	/* map of everyday hero contributors - only where div id="everydayhero_map" */
	if ( $("#everydayhero_map").length > 0 ) {
		$.getScript("/jscripts/jquery.flash.js", function(){
			$('#everydayhero_map').flash({ 
			  src: '/media/eventmap.swf',
			  width: 700,
			  height: 400
			});
        });
	}
	

	
	// load pop up window library
	$.getScript("/jscripts/jquery.popupwindow.js", function(){
		/* pop up windows profiles */
		var profiles =
		{
			window250:
			{
				height:300,
				width:250,
				status:1,
				resizable:0
			},
			windowCenter:
			{
				height:550,
				width:400,
				center:1,
				resizable:0,
				scrollbars:1
			},
			imageCenter:
			{
				center:1,
				resizable:0,
				scrollbars:0,
				width:600,
				height:400
			}			
		};
		if($(".popupwindow").length > 0){
			$(".popupwindow").popupwindow(profiles);
		}
	});
	
	
	$.getScript("/jscripts/jquery.corner.js", function(){
		if($('#content_submenu').length >0){
			$('#content_submenu').corner("top 8px");
			$('#content_submenu>li.last').corner("bottom 8px");
		}
		
		if($(".corner").length>0){
			$('.corner').corner("8px");
		}

		//$('.shop_product').corner("round 8px").css("border","1px solid #b3b38c");
		if($(".shop_product").length>0){
			$('.shop_product').corner("round 8px");
		}
		
		if($("#ambassadors").length > 0){
			$(".tab").corner("top 8px");
		}
	});
		
		
	if ( $("a.lightbox").length > 0 ) {
		$.getScript("/jscripts/slimbox2.js", function(){
		});
	}

	/* map of everyday hero contributors - only where div id="everydayhero_map" */
	if ( $("#sid_gallery").length > 0 ) {
		$.getScript("/jscripts/jquery.galleria.js", function(){
			$('.gallery_steveirwinday_unstyled').addClass('gallery_steveirwinday'); // adds new class name to maintain degradability
		  
			$('ul.gallery_steveirwinday').galleria({
				history   : true, // activates the history object for bookmarking, back-button etc.
				clickNext : true, // helper for making the image clickable
				insert    : '#main_image', // the containing selector for our main image
				onImage   : function(image,caption,thumb) { // add image effects
					
					// fade in the image & caption
					image.css('display','none').fadeIn(1000);
					$(".caption").css('display','none').fadeIn(500).css('width',image.width());
		
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// fade out inactive thumbnail
					_li.siblings().children('img.selected').fadeTo(500,0.3);
					
					// fade in active thumbnail
					thumb.fadeTo('fast',1).addClass('selected');
					
					// add a title for the clickable image
					image.attr('title','Next image >>');
				},
				onThumb : function(thumb) { // thumbnail effects goes here
					
					// fetch the thumbnail container
					var _li = thumb.parents('li');
					
					// if thumbnail is active, fade all the way.
					var _fadeTo = _li.is('.active') ? '1' : '0.3';
					
					// fade in the thumbnail when finnished loading
					thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
					
					// hover effects
					thumb.hover(
						function() { thumb.fadeTo('fast',1); },
						function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
					)
				}
			});
			
			$(".jumpmenu").change(function() {
				var gal = $(".jumpmenu").val();
		
				if (gal != '') {
					var newhref = '/news/photo-gallery/gallery/'+gal;
					location.href= newhref
				}
		
			});	
			
        });
	}
	
	if ( $("#contact_form").length > 0 ) {
		$.getScript("/jscripts/contact_form.js", function(){
		});
	}
	
	// deobfuscate obfuscated email addresses
	if ( $(".Obfuscated").length > 0 ) {
		$.getScript("/jscripts/jquery.obfuscate.js", function(){
		  $('.Obfuscated').deobfuscate();
		});
	}	
	
	// for displaying submenus on mouseover
	if(($("li[id*='menu']").length > 0) && isIE6 == false){
				
		$("li[id*='menu']").each(function (i) {
			var menu_id = $(this).attr("id");
			var submenu_arrow = $("#"+menu_id+" .submenu_arrow");
			$(submenu_arrow).bind("click",function(){
				
				var this_display = $("li."+menu_id).css("display");
				var submenu_img = $("#"+menu_id+" .submenu_arrow img");

				if(this_display == "none"){
					$(submenu_img).attr("src","/images/submenu_arrow_down.gif");
					$(submenu_arrow).attr("title","Collapse menu");
					$("li."+menu_id).slideDown("slow");
				} else {
					$(submenu_img).attr("src","/images/submenu_arrow_up.gif");
					$(submenu_arrow).attr("title","Expand menu");
					$("li."+menu_id).slideUp("slow");
				}
			});
			
		});
	}
	
	//ambassors page
	if($("#ambassadors").length > 0 && isIE6 == false){
		var tabContainers = $('#ambassadors > div.tab');

		// tab click
		$('#ambassadors li a').click(function (event) {
			event.preventDefault();											   
			$("div.ambassador_profile").hide();
			$("div.tab").hide().filter(this.hash).fadeIn("slow");
			
			$('#ambassadors a').removeClass('selected');
			$(this).addClass('selected');
			
			return false;
		}).filter(':first').click();
		
		// thumbnail click
		$('div.tab a.ambassador_thumbnail').click(function (event) {
			//console.log("test");
			event.preventDefault();
			$("div.ambassador_profile").hide().filter(this.hash).fadeIn("4000");
			//location.hash = "";															
			return false;
		});
		
	}
	
	if($("a.new_window").length>0){
   		$('a.new_window').click(function(){
			window.open(this.href);
      		return false;
      	});		
	}
	
	/*
	if(isIE6 == false){
	$.getScript("/jscripts/jquery.pngFix.js", function(){
		$(document).pngFix();
	});
	}
	*/
	

});
