/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: false, // change to true if you want arrows to display for submenu items
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);
/* Copyright (c) 2009 Alvaro A. Lima Jr http://alvarojunior.com/jquery/joverlay.html
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * Version: 0.7.1 (JUN 15, 2009
 * Requires: jQuery 1.3+
 * Packer from http://dean.edwards.name/packer/
 */
(function($){var g=$.browser.msie&&$.browser.version==6.0;var h=null;var i=null;$.fn.jOverlay=function(b){if($('#jOverlay').length){$.closeOverlay()}i=null;if(h!==null){clearTimeout(h)}var b=$.extend({},$.fn.jOverlay.options,b);function center(a){if(b.center){$.center(a)}}var c=this.is('*')?this:'#jOverlayContent';var d=g?'absolute':'fixed';var e=/([^\/\\]+)\.(png|gif|jpeg|jpg|bmp)$/i.test(b.url);var f=b.imgLoading?"<img id='jOverlayLoading' src='"+b.imgLoading+"' style='position:"+d+"; z-index:"+(b.zIndex+9)+";'/>":'';$('body').prepend(f+"<div id='jOverlay' />"+"<div id='jOverlayContent' style='position:"+d+"; z-index:"+(b.zIndex+5)+"; display:none;'/>");$('#jOverlayLoading').load(function(){center(this)});if(g){$('select').hide();$('#jOverlayContent select').show()}$('#jOverlay').css({backgroundColor:b.color,position:d,top:'0px',left:'0px',filter:'alpha(opacity='+(b.opacity*100)+')',opacity:b.opacity,zIndex:b.zIndex,width:!g?'100%':$(window).width()+'px',height:!g?'100%':$(document).height()+'px'}).show();if(this.is('*')){i=this.prev();$('#jOverlayContent').html(this.show().attr('display',b.autoHide?'none':this.css('display')));if(!e){center('#jOverlayContent');$('#jOverlayContent').show();if(!b.url&&$.isFunction(b.success)){b.success(this)}}}if(e){$('<img/>').load(function(){var a=$.resize(this.width,this.height);$(this).css({width:a.width,height:a.height});$(c).html(this);center('#jOverlayContent');$('#jOverlayLoading').fadeOut(500);$('#jOverlayContent').show();if($.isFunction(b.success)){b.success(this)}}).error(function(){alert('Image ('+b.url+') not found.');$.closeOverlay()}).attr({'src':b.url,'alt':b.url})}if(b.url&&!e){$.ajax({type:b.method,data:b.data,url:b.url,success:function(a){$('#jOverlayLoading').fadeOut(500);$(c).html(a).show();center('#jOverlayContent');if($.isFunction(b.success)){b.success(a)}},error:function(){alert('URL ('+b.url+') not found.');$.closeOverlay()}})}if(g){$(window).scroll(function(){center('#jOverlayContent')});$(window).resize(function(){$('#jOverlay').css({width:$(window).width()+'px',height:$(document).height()+'px'});center('#jOverlayContent')})}$(document).keydown(function(a){if(a.keyCode==27){$.closeOverlay()}});if(b.bgClickToClose){$('#jOverlay').click($.closeOverlay)}if(Number(b.timeout)>0){jOverlayTimer=setTimeout($.closeOverlay,Number(b.timeout))}$('#jOverlayContent').css(b.css||{})};$.resize=function(a,b){var x=$(window).width()-150;var y=$(window).height()-150;if(a>x){b=b*(x/a);a=x;if(b>y){a=a*(y/b);b=y}}else if(b>y){a=a*(y/b);b=y;if(a>x){b=b*(x/a);a=x}}return{width:a,height:b}};$.center=function(a){var a=$(a);var b=a.width();a.css({width:b+'px',marginLeft:'-'+(b/2)+'px',marginTop:'-'+a.height()/2+'px',height:'auto',top:!g?'50%':$(window).scrollTop()+($(window).height()/2)+'px',left:'50%'})};$.fn.jOverlay.options={method:'GET',data:'',url:'',color:'#000',opacity:'0.6',zIndex:9999,center:true,imgLoading:'',bgClickToClose:true,success:null,timeout:0,autoHide:true,css:{}};$.closeOverlay=function(){if(g){$("select").show()}if(i!==null){if(i!==null){var a=$('#jOverlayContent').children();i.after(a.css('display',a.attr('display')));a.removeAttr('display')}}$('#jOverlayLoading, #jOverlayContent, #jOverlay').remove()}})(jQuery);
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*/
	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");
	}
	// homepage reg "button"
	if($("div#home-reg").length>0){
		$('div#home-reg').click(function(e){
			location.href= 'khaki-it/';
		});
	}
	// Joey Ambassadors Reg Form
	if ( $("div#joeys").length > 0 ) {
		$('a#show-joeyreg').click(function(e){
			$('div#status').empty();										   
			$('div#joeyreg').jOverlay();
			e.preventDefault();
        });
		$('a#show-joeyfaq').click(function(e){
			$('div#joeyfaq').jOverlay();
			e.preventDefault();
        });		
		$('input#joeyreg_submit').click(function(e){
			
			$('input#joeyreg_submit').attr('disabled',true).attr('value','Registering...');

			var regdata = 'jname=' + $('input#joey_name').val() + '&pname=' + $('input#parent_name').val() + '&age=' + $('input#age').val() + '&add=' + $('input#address').val() + '&email=' + $('input#email').val() + '&phone=' + $('input#phone').val();
			
			$.ajax({
				type: 'POST',
				url: '/includes/process_joeyambassador_regform.php',
				data:  regdata,				
				success: function(results) {
					if(results == 1) {
						$(':input','#joey_reg_form').not(':button, :submit, :reset, :hidden').val('');
						$('input#joeyreg_submit').removeAttr('disabled').attr('value','Register');						
						$('div#status').html('<p style="color:green;">Thanks, we\'ve successfully received your registration!</p>');
						$("#jOverlay, div#joeyreg").delay(3000).fadeOut('slow');
					} else {
						$('div#status').html('<p style="color:red;">There was a problem submitting your registration.  You can try again, or email it to info@wildlifewarriors.org.au instead!');
						$('input#joeyreg_submit').removeAttr('disabled').attr('value','Register');
					}
				}
			});
			e.preventDefault();
		});
		
	}

	
	// 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
			},
			galaForm:
			{
				center:1,
				resizable:1,
				scrollbars:1,
				width:970,
				height:500
			}
			
		};
		if($(".popupwindow").length > 0){
			$(".popupwindow").popupwindow(profiles);
		}
	});
	
	
	$.getScript("/jscripts/jquery.corner.js", function(){
		if($('#fundraiser_countdown').length >0){
			$('#fundraiser_countdown').corner("bottom 4px");
		}
		if($('ul.sf-menu li a.topitem').length >0){
			$('ul.sf-menu li a.topitem').corner("5px");
		}		
		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($("div#primarynav").length>0){
			$('div#primarynav').corner("round 5px");
		}
		if($("div#content").length>0){
			$('div#content').corner("5px");
		}
		if($("div#its_sid").length>0){
			$('div#its_sid').corner("bottom 5px");
		}		
		// homepage second column
		if($("div.second_third_box").length>0){
			$("div.second_third_box").mouseover(function() {
				$('div#' + $(this).attr('id')).css('background-color','#d9d9c6');
			}).mouseout(function(){
				$('div#' + $(this).attr('id')).css('background-color','#ecece2');
			});			
		}

	});
	
	/* SECOND COLUMN */
	$("div.second_third_box").hover(function() {
		hover = $(this).attr('id');
		$('div#' + hover + 'h').css('display','block');
	},function(){
		$('div#' + hover + 'h').css('display','none');
	});
	/* Homepage NL Signup */
	if($("#sid_newsletter_form").length>0){
		$("#sid_newsletter_form").submit(function(e){
			var nl_email = $("#newsletter_txt").val();
			var actionUrl = $("#sid_newsletter_form").attr("action")+"?email="+escape(nl_email);
			var pLeft = (screen.width - 380)/2;
			var pTop = (screen.height - 500)/2;
			var features = 'width=380,height=500,left = ' + pLeft + ',top=' + pTop +',resizeable,scrollbars';
			var opened = window.open(actionUrl, 'formpopup', features);
			if(!opened) alert("Newsletter subscription has been\n blocked by a pop up blocker.");
			return false;
		});
		var cleared = false;
		$("#newsletter_txt").focus(function(){
			if(!cleared){
				$(this).val("");
				cleared = true;
			}
		});
	}

	if ( $("a.lightbox").length > 0 ) {
		$.getScript("/jscripts/slimbox2.js", function(){
		});
	}
	
	if ( $("div#defaultCountdown").length > 0 ) {
		$.getScript("/jscripts/jquery.countdown.min.js", function(){
			//streamTime = $.countdown.UTCDate(2011,11,15,10,30,0);
			$("#defaultCountdown").countdown({until: streamTime, alwaysExpire: true, expiryUrl: '/events/live/'});															  
		});
	}
	
	if ( $("div#fms").length > 0 ) {
		$.getScript("/flowplayer/flowplayer-3.2.4.min.js", function(){
			// install flowplayer into container
			$f("fms", "/flowplayer/flowplayer-3.2.5.swf", {
			   
					// we need at least this version
					version: [9, 115],
					onFail: function()  {
						document.getElementById("info").innerHTML =
							"You need the latest Flash version to view MP4 movies. " +
							"Your version is " + this.getVersion()
						;
					},
					clip: {
						//url: 'livestream',
						//live: true,
						url: "/videos/sid2011.mp4",
						autoPlay: false, 
						autoBuffering: false,
						//provider: 'rtmp'
					}/*,
					plugins: {
					rtmp: {
						url: '/flowplayer/flowplayer.rtmp-3.2.3.swf',
						netConnectionUrl: 'rtmp://freetrip.australiazoo.com.au/live'
					}
					
				}
				*/
			});
		  
		});
	}
	
	/* 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;
      	});		
	}
	
	$('input#cc_subscribe').click(function(e){
		alert('an ajax call to CC here')
		e.preventDefault();	   
	});
	
	/*
	if(isIE6 == false){
	$.getScript("/jscripts/jquery.pngFix.js", function(){
		$(document).pngFix();
	});
	}
	*/
	

});

