/* GLOBAL VARIABLES */

ROOT_URL = ''; // should be at least '/' if site is at document root


/* FUNCTIONS */

$(document).ready(function() {
	/* plugin that handles the multi-level primary navigation */
	$('#primary-links').droppy({speed:200});
	
	/* hide the toggleable content */
	$('.toggle-content').hide();
	$('a.toggle-link').removeClass('opened');
	/* show/hide toggleable content when the icon is clicked */
	$('a.toggle-link').toggle(
		function(){
			$(this).addClass('opened').blur();
			$($(this).attr('href')).parent().addClass('opened');
			if($.browser.msie) {
				$($(this).attr('href')).show();
			} else {
				$($(this).attr('href')).slideDown();
			}
			return false;
		},
		function(){
			$(this).removeClass('opened').blur();
			$($(this).attr('href')).parent().removeClass('opened');
			if($.browser.msie) {
				$($(this).attr('href')).hide();
			} else {
				$($(this).attr('href')).slideUp();
			}
			return false;
		}
	);
	
	
	$('body.page-home #content-links-content > div[id^=content-]').css({'position': 'absolute', 'top': '0px'}).not(':first-child').hide();
	$('body.page-home #content-links-content').height($('#content-links-content > div:first').height()+'px');
	$('body.page-home #content-links li').click(function(){
		if(!$(this).hasClass('active')) {
			if($(this).children(':first').children(':first').attr('href') == 'http://research.schulich.yorku.ca/'){
				window.location = $(this).children(':first').children(':first').attr('href');
				return false;
			}				
			
			$('#content-links li').removeClass('active');
			$(this).addClass('active');
			
			//$('#content-links-content').height($($(this).attr('href')).height()+'px');
			$('#content-links-content').animate({height : $($(this).find('a').attr('href')).height()+'px'}, 250);
			$('#content-links-content > div[id^=content-]').hide();
			$($(this).find('a').attr('href')).fadeIn();
			// sIFR doesn't get applied to hidden elements, so do it as it's being shown.
			if($($(this).attr('href') + ' h2.sIFR-replaced').length == 0) {
				//draw_sifr('h2');
			}
			//return false;
		}
		return false;
	});
	
	
	var default_search = $('#form-search input[type=text]').val('Enter search words here').val();
	$('#form-search input[type=text]').focus(function(){
		if($(this).val() == default_search) {
			$(this).val('');
		}
	});
	$('#form-search input[type=text]').blur(function(){
		if($(this).val() == '') {
			$(this).val(default_search);
		}
	});
	
	// qtip code
	$('.qtip[title]').qtip({
		style:{name:'dark', tip:true, border:{radius:3}},
		position:{
			corner:{target: 'topMiddle',tooltip: 'bottomMiddle'}}
	});
	////////////////////////////////////////////////////////////////////
	
	
	// colorbox code

	// course desciption popup
	$(".coursedesc").click(function(){ 
		//alert($(this).attr('href'));
		$.fn.colorbox({href:"" + $(this).attr('href') + " div.column-last", width:"630px"})
		return false;
	});

	// homepage popups
	$("a.visit_bba").colorbox({width:"600px", inline:true, href:"#visit_bba_inline"} );
	$("a.visit_mba").colorbox({width:"600px", inline:true, href:"#visit_mba_inline"} );

	$("a.specialevent_mba").colorbox({width:"600px", inline:true, href:"#specialevent_mba_inline"} );	

	$("a.meet_bba").colorbox({width:"600px", inline:true, href:"#meet_bba_inline"} );
	$("a.meet_mba").colorbox({width:"600px", inline:true, href:"#meet_mba_inline"} );
	$("a.meet_phd").colorbox({width:"600px", inline:true, href:"#meet_phd_inline"} );
	
	$("a.meet_minoo").colorbox({width:"600px", inline:true, href:"#meet_minoo_inline"} );
	
	$("a.contact_mba").colorbox({width:"600px", inline:true, href:"#contact_mba_inline"} );
	
	$("a.contact_cdc").colorbox({width:"600px", inline:true, href:"#contact_cdc_inline"} );
	
	$("a.experience_schulich").colorbox();

	
	$("a.meet_mba_remote, a.visit_mba_remote, a.meet_bba_remote, a.visit_bba_remote").colorbox({innerWidth:"600px"});
	
	
	
	
	// Study Plan pop-ups (at a glance charts)
	$("a.glance1").colorbox({width:"400px", inline:true, href:"#glance1_inline"} );
	$("a.glance2").colorbox({width:"400px", inline:true, href:"#glance2_inline"} );
	$("a.glance3").colorbox({width:"400px", inline:true, href:"#glance3_inline"} );
	$("a.glance4").colorbox({width:"400px", inline:true, href:"#glance4_inline"} );
	$("a.glance5").colorbox({width:"400px", inline:true, href:"#glance5_inline"} );
	$("a.glance6").colorbox({width:"500px", inline:true, href:"#glance6_inline"} );
	
	// specializations popups
	if (jQuery.url.param('specialization')){
		$mySpecialization = jQuery.url.param('specialization');
		//console.log($mySpecialization);
		
		$("a[href="+$mySpecialization+"]").addClass('active');
		$("a[href!="+$mySpecialization+"]").removeClass('active');
		
		$('div#scc').load("" + $mySpecialization + " div.content_right", function(){
			$("#tabs").tabs({show: function(event, ui) {
				//draw_sifr();
				$('table.stripe tr:even').addClass('odd');
			}});
			
			if (jQuery.url.param('tab')){
				$myTab = jQuery.url.param('tab');
				//console.log($myTab);
			
				var $tabs = $("#tabs").tabs();
				$tabs.tabs('select', $myTab);
			}
						
				$(this).slideDown(1000);
				$(".coursedesc").click(function(){ 
					//alert($(this).attr('href'));
					$.fn.colorbox({href:"" + $(this).attr('href') + " div.column-last", width:"630px"})
					return false;
				});
			});
		
		$("a[rel='specialization-course']").click(function(){ 
			//console.log($(this).attr('href') + ' here');
			$("a[rel='specialization-course']").not(this).removeClass('active');
			$(this).addClass('active');
			//console.log('working?');
			window.location.replace("http://www.schulich.yorku.ca/client/schulich/schulich_lp4w_lnd_webstation.nsf/page/MBA+Graduate+Area+and+Program+Information?OpenDocument&specialization=" + $(this).attr('href'));
			
			/*$('div#scc').load("" + $(this).attr('href') + " div.content_right", 
					function(){
							$("#tabs").tabs({show: function(event, ui) {
								draw_sifr();
								$('table.stripe tr:even').addClass('odd');
							}})
						$(this).slideDown(1000);
						$(".coursedesc").click(function(){ 
							//alert($(this).attr('href'));
							$.fn.colorbox({href:"" + $(this).attr('href') + " div.column-last", width:"630px"})
							return false;
						});
					});*/
			
			return false;
		});
		
		return false;
	}

	$("a[rel='specialization-course']").click(function(){ 
		//console.log($(this).attr('href') + ' here');
		$("a[rel='specialization-course']").not(this).removeClass('active');
		$(this).addClass('active');
		$('div#scc').load("" + $(this).attr('href') + " div.content_right", 
				function(){
						$("#tabs").tabs({show: function(event, ui) {
							//draw_sifr();
							$('table.stripe tr:even').addClass('odd');
						}})
					$(this).slideDown(1000);
					$(".coursedesc").click(function(){ 
						//alert($(this).attr('href'));
						$.fn.colorbox({href:"" + $(this).attr('href') + " div.column-last", width:"630px"})
						return false;
					});
				});
		
		return false;
	});
});

// equal heights fix
function equalHeight(group, height) {
	var tallest = height;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}



