/*

	Ideal Indian School Website,
	Core Javascript.
	
	Written by Tejas Kumar.
	
*/

var about_active_dropdown = 0;
var wings_active_dropdown = 0;
var facilities_active_dropdown = 0;
var staff_active_dropdown = 0;
var others_active_dropdown = 0;
var konamiopen = 0;
var currentribbonnews = 0;

function CheckCompatibility(){

	if(BrowserDetect.browser == "Explorer" && parseFloat(BrowserDetect.version) <= 6){
	
		window.location = 'compatibility.php';
	
	}

}

window.onload = function(){

	setTimeout(function(){ new Fx.Morph('newsribbon', { duration: 'long', transition: Fx.Transitions.Expo.easeInOut }).start({ 'width': [991], 'margin-top': [0] }); }, 550);
	setTimeout(function(){ new Fx.Morph('newsribbon', { duration: 'short', transition: Fx.Transitions.Circ.easeInOut }).start({ 'opacity': [0,1], 'left': [6] }); }, 550);
	
	setInterval(function(){
	
		if(currentribbonnews == -1){
			ribbonnewstochange = oldcurrentribbonnews;
		}else{
			ribbonnewstochange = currentribbonnews;
		}
		
		new Fx.Morph(ribbonnewstochange+'_ribbonnews', { traisition: Fx.Transitions.Expo.easeInOut }).start({ 'opacity': [0], 'left':[0,-500] })
		setTimeout(function(){ $(ribbonnewstochange+'_ribbonnews').style.display = 'none'; }, 2500);
		
		currentribbonnews = currentribbonnews+1;
		
		new Fx.Morph(currentribbonnews+'_ribbonnews', { traisition: Fx.Transitions.Expo.easeInOut }).start({ 'opacity': [1], 'left':[500,0], 'display': 'inline' });
		setTimeout(function(){ $(currentribbonnews+'_ribbonnews').style.display = 'inline'; }, 2500);
		
		if(currentribbonnews == document.getElementsByClassName('ribbonnews').length-1){
		
			oldcurrentribbonnews = currentribbonnews;
			currentribbonnews = -1;
			
		}
		
	}, 5000);

}

window.addEvent('domready', function(){

	$('user_browser').innerHTML = BrowserDetect.browser+' '+BrowserDetect.version;

	$('home_active').addEvents({ 'mouseenter': function(){ Show_Active_Menu_Item('home_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('home_active'); } });
	
	$('about_active').addEvents({ 'mouseenter': function(){ about_active_dropdown = 1; Show_Active_Menu_Item('about_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('about_active'); } });
	
	$('wings_active').addEvents({ 'mouseenter': function(){ wings_active_dropdown = 1; Show_Active_Menu_Item('wings_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('wings_active'); } });
	
	$('committee_active').addEvents({ 'mouseenter': function(){ Show_Active_Menu_Item('committee_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('committee_active'); } });
	
	$('staff_active').addEvents({ 'mouseenter': function(){ staff_active_dropdown = 1; Show_Active_Menu_Item('staff_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('staff_active'); } });
	$('prospectus_active').addEvents({ 'mouseenter': function(){ Show_Active_Menu_Item('prospectus_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('prospectus_active'); } });
	
	$('facilities_active').addEvents({ 'mouseenter': function(){ facilities_active_dropdown = 1; Show_Active_Menu_Item('facilities_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('facilities_active'); } });
	
	$('others_active').addEvents({ 'mouseenter': function(){ others_active_dropdown = 1; Show_Active_Menu_Item('others_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('others_active'); } });
	
	$('careers_active').addEvents({ 'mouseenter': function(){ Show_Active_Menu_Item('careers_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('careers_active'); } });
	$('contact_active').addEvents({ 'mouseenter': function(){ Show_Active_Menu_Item('contact_active'); }, 'mouseleave': function(){ Hide_Active_Menu_Item('contact_active'); } });
	
	$('about_active_dropdown').addEvents({ 'mouseenter': function(){ about_active_dropdown = 0; }, 'mouseleave': function(){ about_active_dropdown = 0; Hide_Active_Dropdown('about_active'); } });
	$('wings_active_dropdown').addEvents({ 'mouseenter': function(){ wings_active_dropdown = 0; }, 'mouseleave': function(){ wings_active_dropdown = 0; Hide_Active_Dropdown('wings_active'); } });
	$('staff_active_dropdown').addEvents({ 'mouseenter': function(){ staff_active_dropdown = 0; }, 'mouseleave': function(){ staff_active_dropdown = 0; Hide_Active_Dropdown('staff_active'); } });
	$('facilities_active_dropdown').addEvents({ 'mouseenter': function(){ facilities_active_dropdown = 0; }, 'mouseleave': function(){ facilities_active_dropdown = 0; Hide_Active_Dropdown('facilities_active'); } });
	$('others_active_dropdown').addEvents({ 'mouseenter': function(){ others_active_dropdown = 0; }, 'mouseleave': function(){ others_active_dropdown = 0; Hide_Active_Dropdown('others_active'); } });
	
	//$$("div#photogallery img").reflect({ 'opacity': 0.15 });

});

function Show_Active_Menu_Item(element){

	new Fx.Morph(element, { duration: 'short' }).start({ 'opacity': [0,1] });
	
	if($(element+'_dropdown')){
	
		$(element+'_dropdown').style.display = 'block';
		
		if(BrowserDetect.browser == "Explorer" && parseFloat(BrowserDetect.version) <= 8){
			
			new Fx.Morph(element+'_dropdown', { duration: 'short' }).start({ 'opacity': [1], 'top': [52] });
			
		}else{
		
			new Fx.Morph(element+'_dropdown', { duration: 'short' }).start({ 'opacity': [0,1], 'top': [52] });
	
		}
	
	}

}

function Hide_Active_Menu_Item(element){
	
	setTimeout(function(){ 
		new Fx.Morph(element, { duration: 'short' }).start({ 'opacity': [1,0.01] });
		
		if(element == 'about_active' || element == 'staff_active' || element == 'wings_active' || element == 'facilities_active' || element == 'others_active'){
		
			if(element == 'about_active' && about_active_dropdown == 1){
	
				Hide_Active_Dropdown('about_active');
	
			}else if(element == 'staff_active' && staff_active_dropdown == 1){
	
				Hide_Active_Dropdown('staff_active');
	
			}else if(element == 'others_active' && others_active_dropdown == 1){
	
				Hide_Active_Dropdown('others_active');
	
			}else if(element == 'facilities_active' && facilities_active_dropdown == 1){
	
				Hide_Active_Dropdown('facilities_active');
	
			}else if(element == 'wings_active' && wings_active_dropdown == 1){
	
				Hide_Active_Dropdown('wings_active');
	
			}
		
		}

	}, 300);
		
}

function Hide_Active_Dropdown(element){
	
	if(BrowserDetect.browser == "Explorer" && parseFloat(BrowserDetect.version) <= 8){
			
			setTimeout(function(){ 
				
				$(element+'_dropdown').style.display = 'none'; 
				new Fx.Morph(element+'_dropdown', { duration: 'short' }).start({ 'height': [191] }); 
				new Fx.Morph(element+'_dropdown_content', { duration: 'short' }).start({ 'opacity': [1] }); 
				
			}, 300);
			
			new Fx.Morph(element+'_dropdown', { duration: 'short' }).start({ 'top': [62], 'height': [0] });
			new Fx.Morph(element+'_dropdown_content', { duration: 'short' }).start({ 'opacity': [1,0] });
		
	}else{
	
			setTimeout(function(){ $(element+'_dropdown').style.display = 'none'; }, 300);
			new Fx.Morph(element+'_dropdown', { duration: 'short' }).start({ 'opacity': [1,0], 'top': [62] });
	
	}

}

function Lights_On(){

	$(document.body).style.background = '#dfeeff';
	$(document.body).style.backgroundImage = 'url(\'images/bg_lite.png\')';
	
	if(BrowserDetect.browser == "Explorer" && parseFloat(BrowserDetect.version) <= 8){

		$('lightlogo').setStyle("opacity","0");
		$('darklogo').setStyle("opacity","1");
		
	}else{
	
		new Fx.Morph('lightlogo', { duration: 'short' }).start({ 'opacity': [1,0] });
		new Fx.Morph('darklogo', { duration: 'short' }).start({ 'opacity': [0,1] });
	
	}
	
	$('Light_Switch').onclick = Lights_Off;
	new Request({ url: 'inc/ajax.php?action=changecolors' }).send();
			
}

function Lights_Off(){

	$(document.body).style.background = '#131f2c';
	$(document.body).style.backgroundImage = 'url(\'images/bg.png\')';

	if(BrowserDetect.browser == "Explorer" && parseFloat(BrowserDetect.version) <= 8){

		$('lightlogo').setStyle("opacity","1");
		$('darklogo').setStyle("opacity","0");
		
	}else{
	
		new Fx.Morph('lightlogo', { duration: 'short' }).start({ 'opacity': [0,1] });
		new Fx.Morph('darklogo', { duration: 'short' }).start({ 'opacity': [1,0] });
	
	}

	$('Light_Switch').onclick = Lights_On;
	new Request({ url: 'inc/ajax.php?action=changecolors' }).send();

}

function Hide_Hot_News(){

	new Fx.Morph('hot_news', { duration: 'short' }).start({ 'top': [0], 'opacity': [1,0] });
	setTimeout(function(){ $('hot_news').style.display = 'none'; }, 500);	

}

function Show_Browser_Warning(){

	new Fx.Morph('browser_warning').start({ 'height': [15,320] });
	
	$('Show_Browser_Warning').innerHTML = 'LESS INFO';
	$('Show_Browser_Warning').onclick = function(){ Hide_Browser_Warning(); return false; }

}

function Hide_Browser_Warning(){

	new Fx.Morph('browser_warning').start({ 'height': [320,15] });

	$('Show_Browser_Warning').innerHTML = 'MORE INFO';
	$('Show_Browser_Warning').onclick = function(){ Show_Browser_Warning(); return false; }

}

function Contact(){

	var name = $('contact_name').value;
	var email = $('contact_email').value;
	var subject = $('contact_subject').value;
	var message = $('contact_message').value;
	
	new Request({ url: 'inc/contact.php', data: 'name='+name+'&email='+email+'&subject='+subject+'&message='+message, onRequest: function(){ DisableContactInputs(); }, onSuccess: function(){ EnableContactInputs(); $('contact_button').value = 'Message Sent!'; } }).send();

}

function DisableContactInputs(){

	$('contact_name').disabled = true;
	$('contact_email').disabled = true;
	$('contact_subject').disabled = true;
	$('contact_message').disabled = true;
	$('contact_button').disabled = true;
	
}

function EnableContactInputs(){

	$('contact_name').disabled = false;
	$('contact_email').disabled = false;
	$('contact_subject').disabled = false;
	$('contact_message').disabled = false;
	$('contact_button').disabled = false;

}

function QP_Next(from,to){

	new Fx.Morph('qp_'+from+'_td', { duration: 'short' }).start({ 'background-color': '#050505' });
	new Fx.Morph('qp_'+to+'_td', { duration: 'short' }).start({ 'background-color': '#561609' });
	
	$('qp_'+from).disabled = true;
	
	if(from == 'subject'){
		
		$('qp_getit_div').style.display = 'inline';
		setTimeout(function(){ $('resetqp').style.display = 'inline'; }, 1000);
		
	}
	
	new Request({ url: 'inc/ajax.php?action=getqps', data: 'from='+from+'&'+from+'='+$('qp_'+from).value, onSuccess: function(response){ $('qp_'+to+'_div').innerHTML = response; } }).send();

}

function ResetQPs(){

	$('qp_term').disabled = false; 
	$('qp_class').disabled = false; 
	$('qp_subject').disabled = false; 
	$('qp_exam').disabled = false; 
	$('qp_year').disabled = false; 
	
	$('qp_getit_div').style.display = 'none';
	$('resetqp').style.display = 'none';
	new Fx.Morph('qp_getit_td').start({ 'background-color': '#050505' });
	new Fx.Morph('qp_class_td').start({ 'background-color': '#561609' });
	
	$('qp_term').style.display = 'none'; 
	$('qp_exam').style.display = 'none'; 
	$('qp_subject').style.display = 'none'; 
	$('qp_year').style.display = 'none'; 

}

function UnlockKonami(){

	if(konamiopen == 0){
	
		$('overlay').style.display = 'inline';
		$('asdfmovie').style.display = 'inline';
	
		new Fx.Morph('overlay', { duration: 'short' }).start({ 'opacity': [0,0.8] }); 
		setTimeout(function(){ new Fx.Morph('asdfmovie', { duration: 'short' }).start({ 'opacity': [0,1] }); }, 500);
		
		if($('slideshow')){
		
			$('slideshow').style.display = 'none';
		
		}
		
		konamiopen = 1;
		
	}else{
	
		setTimeout(function(){ $('overlay').style.display = 'inline';
		$('asdfmovie').style.display = 'inline'; }, 1200);
	
		setTimeout(function(){ new Fx.Morph('overlay', { duration: 'short' }).start({ 'opacity': [0.8,0] }); }, 500);
		new Fx.Morph('asdfmovie', { duration: 'short' }).start({ 'opacity': [1,0] });
		
		if($('slideshow')){
		
			setTimeout(function(){ $('slideshow').style.display = 'inline'; }, 1000);
		
		}
		
		konamiopen = 0;
	
	}

}
