$(window).load(function() {

	//ipad fade bars fix
	// Redirect iPhone/iPod visitors
	function isiPad(){
	    return (
	        (navigator.platform.indexOf("iPad") != -1) 
	    );
	}
	if(isiPad()){
	    //$('body').css({ color: '#459484'});
	      $('#left_fade').css({ minHeight: 3000});
	      $('#left_fade').css({ height: '100%'});
	      $('#right_fade').css({ minHeight: 3000});
	      $('#right_fade').css({ height: '100%'});
	}
	


	//last child for ie7 and ie8
	$("ul#main_nav li:last-child").addClass('last-child');
	$("ul#sub_nav li:last-child").addClass('last-child');
	
	$('.donate_btn').hover(
	function(){		
	    $(this).children('hr').css({
	    				borderColor : '#ffffff'
	    });
	    return false
	},
	function(){
	    $(this).children('hr').css({
	    				borderColor : '#cd171f'
	    });
	    return false
	});
	$('.newsletter_button').hover(
	function(){		
	    $(this).children('hr').css({
	    				borderColor : '#ffffff'
	    });
	    return false
	},
	function(){
	    $(this).children('hr').css({
	    				borderColor : '#000000'
	    });
	    return false
	});	

	//add sub nav for mobile view
//	$('<div class="navigationSelect none">\
//	  <select onchange="location = this.options[this.selectedIndex].value;">\
//	   <option>Menu</option>\
//	     <option value="/about">About us</option>\
//	     <option value="/support">Support us</option>\
//	     <option value="/cafe">Cafe</option>\
//	     <option value="/news">News</option>\
//	     <option value="/exhibitions">Exhibitions</option>\
//	     <option value="/hire">Museum hire</option>\
//	     <option value="/viewing">Private viewing</option>\
//	    </select>\
//	</div>').appendTo('#logo');


	//red panels
	$(".red_panel").parent().click(function(){
	  $(this).css({
	  				opacity : '0.6'
	  });
	  window.location=$(this).find("a").attr("href"); return false;
	});
	$(".red_panel").addClass("animate_red_panel");
	//add hover pointer for panels
	$(".red_panel").parent().css({ 'cursor' : 'pointer'});
	
	
	$.fn.getPanelInfo = function(options) {
	    return this.each(function() {	        
	        var boxHeight = $(this).parent().outerHeight();
	        var panelHeight = $(this).outerHeight();
	        var headingHeight = $(this).children().outerHeight();
	        var subTextHeight = $(this).children('p').outerHeight();
	     	//alert('box height =' + boxHeight + 'panel height =' + panelHeight + 'heading height =' + headingHeight);
	     	//alert('subText height =' + subTextHeight);
	     	//get height to move
	     	var moveBox = (boxHeight - headingHeight) ;
		    $(this).css("margin-top", moveBox+"px");
		    
		    //add the add up down toggle for the panel
		    //reveal whole panel
		    var revealP = (boxHeight - panelHeight);
			//reveal heading and paragraph
		    var revealP2 = (boxHeight - (headingHeight + subTextHeight));
		    $(this).parent().hover(
		    function(){		
		        //$(this).children(".red_panel").css("margin-top", revealP+"px");
		        $(this).children(".red_panel").animate({
		        	'marginTop': revealP2
		        });
		    },
		    function(){
		        //$(this).children(".red_panel").css("margin-top", hideP+"px");
		        $(this).children(".red_panel").animate({
		        	'marginTop': moveBox
		        });
		    });
	    });
	};
	//activate panel placement on load
	$('.red_panel').getPanelInfo();
	
		
	//make events list item clickable
	$(".event_panel").click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	
	$(".event_panel").addClass("jsison");
	$('.event_panel').hover(
	function(){		
	    $(this).children('.event_panel_type').children('h2').children('a').css({
	    				color : '#ffffff'
	    });
	    $(this).children('.event_panel_type').css({
	    				color : '#000000'
	    });
	    $(this).children('.event_panel_type').children().children('.readmore').css({
	    				color : '#000000'
	    });
	    return false
	},
	function(){
	    $(this).children('.event_panel_type').children('h2').children('a').css({
	    				color : '#414042'
	    });
	    $(this).children('.event_panel_type').css({
	    				color : '#414042'
	    });
	    $(this).children('.event_panel_type').children().children('.readmore').css({
	    				color : '#414042'
	    });
	    return false
	});
		


});
//// ---- END ONLOAD



$(window).resize(function() {
	$(".red_panel").parent().unbind();
	$(".red_panel").parent().click(function(){
	  window.location=$(this).find("a").attr("href"); return false;
	});
	$.fn.getPanelInfo = function(options) {
	    return this.each(function() {	        
	        var boxHeight = $(this).parent().outerHeight();
	        var panelHeight = $(this).outerHeight();
	        var headingHeight = $(this).children().outerHeight();
	        var subTextHeight = $(this).children('p').outerHeight();
	     	//alert('box height =' + boxHeight + 'panel height =' + panelHeight + 'heading height =' + headingHeight);
	     	//get height to move
	     	var moveBox = (boxHeight - headingHeight) ;
		    $(this).css("margin-top", moveBox+"px");
		    
		    //add the add up down toggle for the panel
		    var revealP = (boxHeight - panelHeight);
		    //reveal heading and paragraph
		    var revealP2 = (boxHeight - (headingHeight + subTextHeight ));
		    $(this).parent().hover(
		    function(){		
		        //$(this).children(".red_panel").css("margin-top", revealP+"px");
		        $(this).children(".red_panel").animate({
		        	'marginTop': revealP2
		        });
		    },
		    function(){
		        //$(this).children(".red_panel").css("margin-top", hideP+"px");
		        $(this).children(".red_panel").animate({
		        	'marginTop': moveBox
		        });
		    });
	    });
	};
	//activate panel placement on load
	$('.red_panel').getPanelInfo();
	
	
		
	
});
// END RESIZED FUNCTIONS	

