$(document).ready(function(){

	// if ie6 lets patch it up
	version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if(version < 7) {
		$.ie6fixes();
	}

	// preload images
	// if we remove the slash at the front it will work on localhost home page but mod_rewrite urls dont work
	// keeping the slash will make it work on live server as it will go from the root domain 
	$.preloadImages(
		"images/btn_getinvolved.gif",
		"images/btn_getinvolved-r.gif",
		"images/btn_healing.jpg",
		"images/btn_healing-r.jpg",
		"images/btn_involved.jpg",
		"images/btn_involved-r.jpg",
		"images/btn_itenary.jpg",
		"images/btn_itenary-r.jpg",
		"images/btn_donate.jpg",
		"images/btn_donate-r.jpg",
		"images/footicon_streets.jpg",
		"images/footicon_streets-r.jpg",
		"images/footicon_international.jpg",
		"images/footicon_international-r.jpg",
		"images/footicon_events.jpg",
		"images/footicon_events-r.jpg",
		"images/footicon_haveyoursay.jpg",
		"images/footicon_haveyoursay-r.jpg",
		"images/sillouette.gif",
		"images/mailicon.gif",
		"images/89.gif"
	);
	
	// fadeout flash messages on click
	$('.cancel').click(function(){
		$(this).parent().fadeOut();
		return false;
	});

	// fade out good flash messages after 3 seconds
	$('.flash_good').animate({opacity: 1.0}, 3000).fadeOut();
	
	$('ul#resourcelist li ul li').hide();
	
	//resourcelist dropdowns
	$('ul#resourcelist li a.restitle').click(
		function(){	
			if($(this).parent().find("ul li").css('display') == "none")
			{
				$(this).parent().find("ul li").show("slide", { direction: "up" }, 1000); 
			} else {
				$(this).parent().find("ul li").hide("slide", { direction: "up" }, 1000); 
			}
			return false;
		}
	);
	
	//people said dropdowns
	$('ul#peoplesaid li a').click(
		function() {
			if($(this).parent().find("div").css('display') == "none")
			{
				$(this).parent().find("div").show("slide", { direction: "up" }, 1000); 
			} else {
				$(this).parent().find("div").hide("slide", { direction: "up" }, 1000); 
			}
			return false;
		}
	);
	
	//who we are switching people
	$('#whoweare_content div').hide();
	$('#whoweare_content div.default').show();

	$('ul#whoweare li a').click(function() {
		//remove all blue classes
		//and add blue class to the one we clicked
		$('ul#whoweare li a').removeClass("blue");
		$(this).addClass("blue"); 
		
		//show the div based on the links title and hide all others
		var title = $(this).attr('title');
		$('#whoweare_content div').hide();
		$('#whoweare_content div.'+title).show();
		
		$('#whoweare_photo').attr('src', $('#whoweare_content div.'+title).find("img").attr('src'));
		
		//return false to stop taking you to href target
		return false;
	});
	
	$('#video_display').html($('.media_gallery:first div').html());
	
	//jonesy video stuff
	$('.media_gallery a').click(function() {
		var html = $(this).parent().find("div").html();
		$('#video_display').html(html);
		return false;
	});
	
	
	//load the first item on page load
	//var html = $('ul#pointoflife li a.blue').parent().find("div").html();
	//$('#pointoflife_content').html(html);
	
	//clicking an item change to blue and load 
	$('ul#pointoflife li a').click(function() {
		$('ul#pointoflife li a').removeClass("blue");
		$(this).addClass("blue"); 
		
		var html = $(this).parent().find("div").html();
		$('#pointoflife_content').html(html);
		return false;
	});	
	
	//click on iternational submenu changes content 
	$('#international_submenu li div').hide();
	$('#international_submenu li a').click(function() {
		var html = $(this).parent().find("div").html();
		$('#international_content').html(html);
		return false;
	});
	
	$("ul#bestvids li a").fancybox({
		'hideOnContentClick': false 
	});
	
	//click on iternational submenu changes content 
	$('#healing_links li div').hide();
	$('#healing_links li a').click(function() {
		$('ul#healing_links li a').removeClass("blue");
		$(this).addClass("blue"); 
		
		var html = $(this).parent().find("div").html();
		$('#healing_content').html(html);
		return false;
	});
	
	$("a#maps").fancybox({
			'frameWidth': 425, 
			'frameHeight': 350,
			'hideOnContentClick': false
	});
			
});











/*
	Preload Images Function
*/
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

/*
	Jonesys custom function to make items on top of pngs in ie6 clickable
*/

jQuery.pngLinks = function() {
	$("a").each(
		function( intIndex ){
			$(this ).css({ position: "relative"});
		}
	);
	$("input").each(
		function( intIndex ){
			$(this ).css({ position: "relative"});
		}
	);
}

/*
	Jonesys ie6 fixes function
*/

jQuery.ie6fixes = function() {
	$(document).pngFix({sizingMethod:"crop"});
	$(".textbox_middle").pngFix({sizingMethod:"scale"});

	$('a.home:hover').css({backgroundPosition: '0px 40px'});
	//$('a.listen').css({background-position-x: '-73px',  background-position-x: '0px'});
	
	$.pngLinks();
}
