var preload = Array(
"images/menu_items/home_menu_current.gif", 
"images/menu_items/alumni_menu_current.gif", 
"images/menu_items/getting_started_menu_current.gif", 
"images/menu_items/iinsider_menu_current.gif", 
"images/menu_items/institute_menu_current.gif", 
"images/menu_items/program_menu_current.gif",  
"images/menu_items/home_menu_hover.gif", 
"images/menu_items/alumni_menu_hover.gif", 
"images/menu_items/getting_started_menu_hover.gif", 
"images/menu_items/iinsider_menu_hover.gif", 
"images/menu_items/institute_menu_hover.gif", 
"images/menu_items/program_menu_hover.gif",
"images/submenu_li_hover.gif");


$(document).ready(function(){
	// ============================
	// = Preload main menu images =
	// ============================
	$.each(preload,function(i,n){
		var img = new Image();
		img.src = n;
	});
	
	// ======================================
	// = Set up the nice in-textbox labels. =
	// ======================================
	textBoxLabelFromValue($("#search_top, #search_bottom, #iinsider_subscribe, #enter_email_input, .enter_email_input"));
	
	if($.browser.safari) {
		$("#enter_email_input, .enter_email_input").each(function(){
			$(this).height(26).width(99).css("fontSize", "13px");
		});
	}
	
	// ========================
	// = Fadelink property... =
	// ========================
	$("a.fadelink").hover(function(){
			$(this).children("img").fadeTo(1, 0.7);
		},function(){
			$(this).children("img").fadeTo(1, 1);
		});
	
	$("#content_container, #page_content").append('<div class="clear"></div>');
	
	// ===================
	// = First menu item =
	// ===================
	$("#main_menu ul").children("li:first").addClass("first");
	
	// ========================
	// = Submenus first items =
	// ========================
	$(".submenu ul").each(function(){
		$(this).children("li:first").addClass("first");
	});
	
	// ==============
	// = Drop downs =
	// ==============
	var totalMenus = $("#main_menu").children("ul").children("li").children("a").length;
	
	$("#main_menu").children("ul").children("li").children("a").hover(function(){
		// link mouseover
		var id = $(this).parent().get(0).id;
		if(!($(this).parent().get(0).className.indexOf('first') > -1 && $(this).get(0).className.indexOf('current') > -1)){
			$(this).add($(this).parent().get(0)).addClass("hover");
			if($.browser.msie) {
				$("select").css("visibility", "hidden");
			}
			$('#'+id+'_submenu').show();
		}
	},function(){
		// link mouseout
		var id = $(this).parent().get(0).id;
		if(!($(this).parent().get(0).className.indexOf('first') > -1 && $(this).get(0).className.indexOf('current') > -1)){
			$(this).add($(this).parent().get(0)).removeClass("hover");
			if($.browser.msie) {
				$("select").css("visibility", "visible");
			}
			$('#'+id+'_submenu').hide();
		}
	}).end().each(function(menuIndex){
		// alert(index);
		var id = this.id;
		// taking the id of the links, finding the divs, and attaching behavior.
		$('#'+id+'_submenu').hover(function(){
			$('#'+id).add($('#'+id).children().get(0)).addClass("hover");
			if($.browser.msie) {
				$("select").css("visibility", "hidden");
			}
			$(this).show();
		},function(){
			$('#'+id).add($('#'+id).children().get(0)).removeClass("hover");
			if($.browser.msie) {
				$("select").css("visibility", "visible");
			}
			$(this).hide();
		}).mousemove(function(){
			$('#'+id).add($('#'+id).children().get(0)).addClass("hover");
			if($.browser.msie) {
				$("select").css("visibility", "hidden");
			}
			$(this).show();
		}).each(function(){
			// set the absolute left position for each dropdown submenu.
			var id = this.id.split('_submenu')[0];
			$(this).css("left", $('#'+id).children("a").position().left+'px');
			// sets the left position for the last menu item so it swings to the left instead of right
			//if(menuIndex == totalMenus-1) {
			//	var offset = 187 - $("#"+id).outerWidth() + 1;
			//	$(this).css("left", ($('#'+id).children("a").position().left - offset)+'px');
			//}
		});
	});
	
	// =======================
	// = Quicklinks dropdown =
	// =======================
	
	$("#quicklinks").hover(function(){
		$(this).addClass("hover");
		$("#quicklinks_dropdown").show();
	},function(){
		$(this).removeClass("hover");    
		$("#quicklinks_dropdown").hide();
	});
	$("#quicklinks_dropdown").hover(function(){
		$("#quicklinks").addClass("hover");
		$(this).show();
	},function(){
		$("#quicklinks").removeClass("hover");
		$(this).hide();
	});
	
	loadPyramid();
	wirePhoneMask();
	
});


// =====================
// = Global functions. =
// =====================


function textBoxLabelFromValue(jQueryNode) {
	jQueryNode.each(function(){
		if($(this).get(0).nodeName == "INPUT" && ($(this).attr("type") == "text") && $(this).val() != ""){
			var startText = $(this).val();
			$(this).focus(function(){
				if($(this).val() == startText){
					$(this).val("");
				}
			}).blur(function(){
				if($(this).val() == ""){
					$(this).val(startText);
				}
			}).val(startText);
		}
		else {
			return false;
		}
	});
}

function searchBoxOnFocus(txtBox)
{
    txtBox.value = '';
}

function searchBoxOnBlur(txtBox)
{
    if(txtBox.value.length == 0)
    {
        txtBox.value = 'Search';
    }
}


function loadLargeFlashMovie(flvToPlay, backgroundImage, container)
{
    var so = new SWFObject("/app_themes/default/video/flv_player.swf", "mymovie", "485", "329", "8", "#ffffff");
	so.addParam("wmode", "transparent");
	so.addVariable("videoToPlay", flvToPlay);
	so.addVariable("imageToLoad", backgroundImage);
	so.useExpressInstall('/app_themes/default/video/expressinstall.swf');
	so.write(container);
}


function loadSmallFlashMovie(flvToPlay, backgroundImage, container, vidWidth, vidHeight, vidX, vidY)
{
    var so = new SWFObject("/app_themes/default/video/mini_flv_player.swf", flvToPlay + "_mymovie", "135", "176", "8", "#ffffff");
	so.addParam("wmode", "transparent");
	so.addVariable("videopath", flvToPlay);
	so.addVariable("imagepath", backgroundImage);
    so.addVariable("vidWidth",vidWidth);
	so.addVariable("vidHeight",vidHeight);
	so.addVariable("vidX",vidX);
	so.addVariable("vidY",vidY);
	so.useExpressInstall('/app_themes/default/video/expressinstall.swf');
	so.write(container);
}


function loadPyramid()
{
    if(!document.getElementById('pyramid_container'))
    {
        return;
    }     
    var so = new SWFObject("../app_themes/default/video/pyramid.swf", "pyramid", "294", "317", "8", "#ffffff");
	so.addParam("wmode", "transparent");
	so.useExpressInstall('app_themes/default/video/expressinstall.swf');
	so.write('pyramid_container');
}


function wirePhoneMask()
{   
    //////////added by Kagan Yilmaz on 06/06/2008
    var phoneMask = new Mask("(###) ###-####");
    if(document.getElementsByTagName)
    {
        var inputs = document.getElementsByTagName("input");
     
        for(var i = 0; i < inputs.length; i++)
        { 
            if(inputs[i].id.indexOf("hone") > 1) //phone
            {
                phoneMask.attach(document.getElementById(inputs[i].id));
            }
        }
    }
    //////////////
    
    
    //phoneMask.attach(document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolder1_cphCenter_cphMainContent_crfRequestForm_txtPhone'));
	
	if(!document.getElementById('contactForm') || !document.getElementById('ctl00_ctl00_ctl00_ContentPlaceHolder1_cphCenter_cphMainContent_crfRequestForm_txtPhone'))
    {
        return;
    }
                                                
}



