$(document).ready(function(){

	//this is required for the PNG in ie6 fix to work.
	if (window.DD_belatedPNG)
		DD_belatedPNG.fix('.pngimg');

	//this is some javascript to stop IE from displaying the img alt attributes when you mouse over imagess.
	var tmpalt;
	$("img").hover( 
		function(){ tmpalt = $(this).attr( "alt" ); $(this).attr( "alt", "" ); },
		function(){ $(this).attr( "alt", tmpalt ); });
		
	//TopNav starts here
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	
	var config = {
		sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
		interval: 100, // number = milliseconds for onMouseOver polling interval
		over: makeTall, // function = onMouseOver callback (REQUIRED)
		timeout: 400, // number = milliseconds delay before onMouseOut
		out: makeShort // function = onMouseOut callback (REQUIRED)
	};
	$("ul.topnav li").hoverIntent(config).hover(function() {
		$(this).addClass("subhover"); //On hover over, add class “subhover”
	}, function(){ //On Hover Out
		$(this).removeClass("subhover"); //On hover out, remove class “subhover”
	});
	
	//Top nav functionality
	$('a.show_hide').live('click',function(){
		var target = $(this).attr('href');
		if( $(target).hasClass('hidden')) {
			$('.hiddendiv').each(function(){
				$(this).fadeOut('slow');
				$(this).addClass('hidden');
			});
			$(target).fadeIn('slow');
			$(target).removeClass('hidden');
			//$(target).addClass('body');
			$.scrollTo('#glass', 1000, {easing:'swing'});//automatic scrolling of the page
		}
		return false;
	});
	
	//top_nav "ubicacion"
	$("a.googlemap").colorbox({html:'<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"\
		src="http://maps.google.com.mx/maps/ms?msa=0&amp;msid=116702937880618057238.00047e55fe9ce9da9cf52&amp;ie=UTF8&amp;source=embed&amp;ll=19.530828,-96.896421&amp;spn=0.003175,0.004801&amp;output=embed"></iframe>'
		,width:'60%',height:'60%', opacity:0.80
	})
	
	$("a.gstreetview").colorbox({html:'<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"\
		src="http://maps.google.com.mx/maps?f=q&amp;source=embed&amp;hl=es&amp;geocode=&amp;q=+Independencia,+Xalapa+Enr%C3%ADquez,+Veracruz-Llave&amp;sll=19.555301,-96.949861&amp;sspn=0.008816,0.01929&amp;ie=UTF8&amp;hq=&amp;hnear=Independencia,+Xalapa+Enr%C3%ADquez,+Veracruz-Llave&amp;t=h&amp;layer=c&amp;cbll=19.530902,-96.896774&amp;panoid=VVj42kfyF1IhP4G6N6prmg&amp;cbp=12,55.49,,0,16.03&amp;ll=19.530876,-96.896676&amp;spn=0,0.002006&amp;z=14&amp;output=svembed"></iframe><br /><small><a href="http://maps.google.com.mx/maps?f=q&amp;source=embed&amp;hl=es&amp;geocode=&amp;q=+Independencia,+Xalapa+Enr%C3%ADquez,+Veracruz-Llave&amp;sll=19.555301,-96.949861&amp;sspn=0.008816,0.01929&amp;ie=UTF8&amp;hq=&amp;hnear=Independencia,+Xalapa+Enr%C3%ADquez,+Veracruz-Llave&amp;t=h&amp;layer=c&amp;cbll=19.530902,-96.896774&amp;panoid=VVj42kfyF1IhP4G6N6prmg&amp;cbp=12,55.49,,0,16.03&amp;ll=19.530876,-96.896676&amp;spn=0,0.002006&amp;z=14" style="color:#0000FF;text-align:left"></iframe>'
		,width:'60%',height:'60%', opacity:0.80, scrolling:false
	})
	
	//top_nav "croquis"
	$("a.croquis").colorbox({href:'images/croquis.png', opacity:0.80})
	
	//top_nav "niveles educativos"
	$('.niveles_box').click(function(){
		var source =  $(this).attr('href');
		source = source.substring(1);
		$.fn.colorbox({html:'<embed width="95%" height="100%" name="plugin" src="PDFs/'+ source +'.pdf" type="application/pdf" pluginspage="http://get.adobe.com/reader/"/>',width:'80%',height:'80%', opacity:0.80})
	});
	
	//top_nav "niveles educativos - padres de familia"
	$('.padres_box').click(function(){
		var source =  $(this).attr('href');
		source = source.substring(1);
		$.fn.colorbox({href:"html/Padres_de_Familia/"+source+".html", iframe:true, width:'80%',height:'80%', opacity:0.80})
	});
	
	$('#videos_btt').click(function(){
		$.fn.colorbox({href:"html/videos.html", iframe:true, width:'650px',height:'80%', opacity:0.80})
	});

	//accordion
	/* Binding Events to the slides */
	$('.slide')
	.bind('open', function(){
		if(! $(this).hasClass('open')){
			$(this).next().trigger('open');
			$(this).addClass('open');
			$(this).animate({right: "-=703px"}, 900, 'swing');
		}
		else{
			$(this).prev().trigger('close');
		}
		$(this).siblings().removeClass('active');
		$(this).addClass('active');
	})
	.bind('close', function(){
		if($(this).hasClass('open')){
			$(this).removeClass('open');
			$(this).animate({right: "+=703px"}, 900, 'swing');
			$(this).prev().trigger('close');
		}
	})

	/* Triggering from the buttons */
	$('.slidebutton').click(function() {
		$(this).parent().trigger('open');
	});
	
	/* Auto Trigger for accordion */
	var interval = 1;
	setInterval(function (){
			//alert(interval);
			switch(interval){
				case 1:
					$("#slidebutton1").parent().trigger('open');
					break;
				case 2:
					$("#slidebutton2").parent().trigger('open');
					break;
				case 3:
					$("#slidebutton3").parent().trigger('open');						
			}
			interval++;
			if (interval == 4) interval = 1;
	},8000);
	
	//this allows colorbox to be closed on image click
	$(document).bind('cbox_complete', function(){ 
		$('#cboxPhoto').unbind().click($.fn.colorbox.close);
	});
	
	//this allows the glass' images to be shown on a colorbox
	$('#gallery_container img').click( function(){
		var source = $(this).attr('src');
		source = source.substring(22,source.indexOf('&'));
		$.fn.colorbox({href:source, opacity:0.80, maxHeight:"1024px", maxWidth:"768px"});
	});
	
	$('.albums').colorbox({iframe:true, opacity:0.80,width:'900px',height:'650px',scrolling:false});
	
	// Contact Form Send
	$("#submit_button").click(function(){
		var nombre = $("#form_name").val();
		var mail = $("#form_mail").val();
		var asunto = $("#form_asunto").val();
		var text = $("#form_txtarea").val();
		var dataString = "sender_subject=" +asunto+ "&sender_email=" +mail+ "&sender_name=" +nombre+ "&sender_message=" +text;
		
		$.ajax({
			type: "POST",
			url: "inc/mail.php",
			data: dataString,
			cache: false,
			success: function(html) {
				$("#contact_success").fadeIn("slow");
				$("#form_name").val("");
				$("#form_mail").val("");
				$("#form_asunto").val("");
				$("#form_txtarea").val("");
				setTimeout(function (){
					$("#contact_success").fadeOut("slow");
				},5000);
			}
		});
	});
	
	/*Organigrama*/
	//$('#organigrama_pic').colorbox({href:"images/organigramag.jpg", opacity:0.80, scrolling:true, maxWidth:"100%", maxHeight:"100%"});
	
	/*hide & seek footer*/
	$("#show_footer").mouseenter(function(){
		$("#footer-wrap").animate({marginBottom: '0px'}, 500, 'swing');
	});
	
	$("#body-wrapper").mouseenter(function(){
		$("#footer-wrap").animate({marginBottom: '-78'}, 500, 'swing' );
	});
	
});

function makeTall() { $(this).find("ul.subnav").slideDown('fast').show();}
function makeShort() { $(this).find("ul.subnav").slideUp('normal');}

