﻿$(function()
{	
	/***********************************************************************
		onClick event finds the child div element, of the li that 
		is clicked, that needs to be dropped down. Uses the built in 
		slideToggle() function to hide and show the "div" element
	***********************************************************************/
	$(".utilityNavigation a").click(function()
	{	
		var clickedObject = $(this).next("div");
		var adjustedLeft = 3;
		var adjustedTop = 10;
		
		var offset = $(this).offset();
		
		var offsetParent = $(".utilityNavigation").offset();
		var xPositionOffsetParent = offsetParent.left;
		
		var xPosition = offset.left;
		var yPosition = offset.top;
		
		xPosition = parseInt(xPosition) - xPositionOffsetParent + adjustedLeft;
		yPosition = parseInt(yPosition) - adjustedTop;

		$(clickedObject).css("top", yPosition);
		$(clickedObject).css("left", xPosition);
		
		if($(clickedObject).css("display") == "block")
		{
			clearAllUtilityNav();
			$(clickedObject).css("display", "none");
			clearAllOnStateNav();
		}
		
		else
		{
			clearAllUtilityNav();
			$(clickedObject).css("display", "block");
			clearAllOnStateNav();
			onState($(this));
		}
	});
	
	/***********************************************************************
		the hover on/off state image change for the Utility Navigation
	***********************************************************************/
	$(".utilityNavigation").children("a").hover(
		function()
		{
			onState($(this));
		},
		
		function()
		{
			// checks whether the utility navigation has its display div open or not
			if($(this).next("div").css("display") != "block")
			{
				// if it does not then show the OFF state of the 
				offState($(this));
			}
		}
	);
});


	/***********************************************************************
		Do Search
	***********************************************************************/

$(document).ready(function(){

	$("#searchgo").click(function(){
	  //$(".globalSearch").animate({ opacity: "hide" }, "slow");
	});

});









	/***********************************************************************
		toggle the advanced search and basic search by class name
	***********************************************************************/

$(document).ready(function(){

	$(".showbasicSearch").click(function(){
	  $(".searchBasic").animate({ opacity: "show" }, "slow");
	});

});

$(document).ready(function(){
	$(".showAdvancedSearch").click(function(){
	  $(".searchAdvanced").animate({ opacity: "show" }, "slow");
	  $(".searchBasic").animate({ opacity: "hide" }, "slow");
	});
});

/***********************************************************************
	closes all Utility Navigation Divs
***********************************************************************/
function clearAllUtilityNav()
{
	$(".utilityNavigation a").next("div").css("display", "none");
}

/***********************************************************************
	sets all of the ON state images in the Utility Navigation to 
	their OFF state
***********************************************************************/
function clearAllOnStateNav()
{
	var utilityNavigationContainer = $(".utilityNavigation").children("a");
	
	for(var i = 0; i < utilityNavigationContainer.size(); i++)
	{
		var imageElement = $(".utilityNavigation").eq(i).children("a");
		
		$(imageElement).css("background-position", "top");
	}
}

/***********************************************************************
	changes the Utility Navigation Image to it's ON state
***********************************************************************/
function onState(id)
{
	$(id).css("background-position", "bottom");
}

/***********************************************************************
	changes the Utility Navigation Image to it's OFF state
***********************************************************************/
function offState(id)
{
	$(id).css("background-position", "top");
}

/***********************************************************************
	toggles the visibility of an element
***********************************************************************/
function toggleVisibility(elementId)
{
    if($get(elementId))
    {
        $get(elementId).style.visibility = ($get(elementId).style.visibility != 'hidden' ? 'hidden' : 'visible' );
    }
}



function toggleDisplay(elementId)
{
    if($get(elementId))
    {
        $get(elementId).style.display = ($get(elementId).style.display != 'none' ? 'none' : '' );
    }
}


var forcedRefresh = true;
var alreadyopen = new Array();
var newwin = new Array();



function openCenteredWindow(theURL, winName, features, w, h){
  var winl = parseInt((screen.width - w - 10) / 2);
  var wint = parseInt((screen.height - h - 29) / 2);
  var retval = openWindow(theURL, winName, features + ',height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl);
  if(!theURL) return retval;
}

function openWindow(theURL, winName, features){
  if(forcedRefresh == false && alreadyopen[winName] && !newwin[winName].closed){
    newwin[winName].focus();
  }
  else{
    alreadyopen[winName] = 1;	 
    newwin[winName] = window.open(theURL, winName, features);
    newwin[winName].focus();
  }
  if(!theURL) return newwin[winName];
}
function openCampusTourWindow(url) {
	openCenteredWindow(url,'CampusTour','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no','800','550');
}

/*********************************************************************************************
	Popup window function
*********************************************************************************************/
function newWindow(url, width, height)
{
    var popWin = window.open(url, '_blank', 'width=' + width + ',height=' + height + ',scrollbars=1,resizable=1');
    if (popWin != null)
    {
        popWin.focus();
    }
}

function SendScriptErrorEmail(url, status, message)
{
    try
    {
        EDMC.ArtInstitute.Web.SendError.SendEmailErrorMessage(url, status, message, SucceededCallback);
    }
    catch(err)
    {
        //alert("A script error has occurred");
    }
}

function SucceededCallback(result)
{
    
}
//This script will activate flash objects on load
objects = document.getElementsByTagName("object");
for (var i = 0; i < objects.length; i++)
{
    objects[i].outerHTML = objects[i].outerHTML;
}

function firemodal(modalname){
    try
    {
        //document.getElementById('inquiryDaemonHolder').style.display = 'block';
        $find(modalname).show();
        return false;
    }
    catch(e)
    {
        
    }
} 

 function GetFirstLevelDirectory()
    {
        var thisUrl = document.URL.toString().toLowerCase();
        
        thisUrl = thisUrl.replace("http://", "");
        thisUrl = thisUrl.replace("www.", "");
        thisUrl = thisUrl.replace(document.domain, "");

        var directories = thisUrl.split('/');
        for(i=0; i<directories.length; i++)
        {
            if(directories[i].indexOf('.')<0)
            {
              return directories[i];
            }           
        }
        return "";
    }
    
function RssClick()
{
     try
        {
             <!-- 
            /* Copyright 1997-2004 Omniture, Inc. */
            s.events='event22'         
            /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
            var s_code=s.t();if(s_code)document.write(s_code)
            //-->
        }
        catch(e){   }
}
