
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};

/* Check for Flash
 **************************************************/

var ua						= navigator.userAgent.toLowerCase();
var isIE					= navigator.appVersion.indexOf("MSIE")!=-1;
var isWin					= navigator.appVersion.indexOf("Windows")!=-1;
var requiredFlashVersion	= 9;
var flashVersion			= 0;
var bFlash					= false;
var bAJAX					= false;

//I've take this out, because it was reading the users old flash version, even after updating to the latest player....Martin 6/11/08
var fv = "";// ReadCookie("FlashVersion")

if(fv!="")
{
	flashVersion	= parseInt(fv);
	bFlash			= flashVersion>=requiredFlashVersion;
	bAJAX			= ReadCookie("AJAXEnabled")=="1";
} 
else 
{
	// AJAX TEST ==========================================================================
	// ====================================================================================
	var xhr = null;
	if(isIE&&isWin)
	{
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP.4.0");
			bAJAX = true;
		}
		catch(e)
		{
			try
			{
				xhr	= new ActiveXObject("Microsoft.XMLHTTP");
				bAJAX = true;
			}
			catch(e)
			{
			}
		}
	}
	else
	{
		try
		{
			//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			xhr	= new XMLHttpRequest();
			bAJAX = true;
		}
		catch(e)
		{
		}
	}
	xhr = null;


	// FLASH TEST =========================================================================
	// ====================================================================================
	var minVersion = 2;
	var maxVersion = 20;
	var installedVersions = "";

	if(isIE && isWin)
	{
		document.write("<scri"+"pt language=\"VBScript\"\>\n");
		document.write("on error resume next \n");
		
		document.write("for f="+minVersion+" to "+maxVersion+" \n");
		document.write("dim o \n");
		document.write("Set o = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\"&f) \n");
		document.write("if IsObject(o) then \n");
		document.write("if (Len(o.GetVariable(\"$version\"))>0) then \n");
		document.write("flashVersion = f \n");
		document.write("end if \n");
		document.write("end if \n");       
		document.write("next \n");
		document.write("</scri" + "pt\>\n");
	}

	if (navigator.plugins){
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			flashVersion = parseInt( flashDescription.split(" ")[2].split(".")[0] );
			//flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			
		}
	}
	if((ua.indexOf("opera")!=-1&&!isWin)) flashVersion = 0;
	
	bFlash = flashVersion>=requiredFlashVersion;
	
	sAJAX = bAJAX ? "1" : "0";
	
	WriteCookie("FlashVersion",flashVersion,null);
	WriteCookie("AJAXEnabled",sAJAX,null);
}

/****************************************************/

//bFlash = false;

/* XHMLHTTP
*/
function getXmlHttpRequest()
{

    var xhr;
	if(isIE&&isWin)
	{
		try
		{
			xhr = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		}
		catch(e)
		{
			try
			{
				xhr	= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
			}
		}
	}
	else
	{
		try
		{
			//netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
			xhr = new XMLHttpRequest();
		}
		catch(e)
		{
			//alert(e);
		}
	}
	return xhr;
};
/* Flash control
 **************************************************/
var FlashControl = {

  flash : bFlash,
  initialize : function() {
    try {
        $("ctl00_ContentPlaceHolder_UniversityList").style.display = (this.flash ? "none" : "");
        if(this.flash) {
        
            var flashVars	= {
	            assetpath: "../media/swf/assets/",
			    datasrc: "../xml/universities.xml?v=" + ServerVariables.ver
	        };
	        var params = {
                wmode: "transparent"
            };
            
            //If the deeplink is set then open up the finder window
            if($("ctl00_txtDeepLink").value.length>0) {
                flashVars.deeplink = $("ctl00_txtDeepLink").value;
            }
            swfobject.embedSWF( "../media/swf/UniFinder.swf?v=" + ServerVariables.ver, "Finder", "936", "470", "9.0.0","media/swf/expressInstall.swf",flashVars, params);
	        
	        $("Finder").style.display = "";

        }
        else {
            //If the deeplink is set then open up the finder window
            if($("ctl00_txtDeepLink").value.length>0) {
                WindowUtil.openWindow($("ctl00_txtDeepLink").value);
            }
        }	     
    }
	catch(e)
	{
	    alert(e);
	}
  },
  
  initializeVideo : function() {
  
    try {
        if(this.flash) {
            var flashVars = {
                videoWidth:  "480",
                videoHeight: "270",
                buffer: "2",
                skinSrc:"../media/swf/assets/VideoSkin.swf"
            };
            
            var params = { 
		        movie:"../media/swf/UniFLVPlayer.swf", 
		        bgcolor:"#000000", 
		        allowScriptAccess:"sameDomain",
		        allowFullScreen:"true"
	        };
    	    
	        var attributes = {
                id: "FlashPlayerControl",
                name: "FlashPlayerControl"
	        };
            
            swfobject.embedSWF("../media/swf/UniFLVPlayer.swf?v=" + ServerVariables.ver,'FlashPlayerControl',"480","270",'9.0.0','/script/expressInstall.swf',flashVars,params,attributes );
        }else {
            $("video").innerHTML = "<div class='noFlashMsg'><h3><span>Hello, you either have JavaScript turned off or an old version of Adobe's Flash Player.</span></h3> " +
                                        "<a href='http://www.macromedia.com/go/getflashplayer/' target='_blank'>" +
                                        "To get latest Flash player please click here</a>." +
                                    "</div>";    
        }
        
    }   
    catch(e)
    {
        alert("initializeVideo: " + e);
    }
  }
};

/* Opens and closes the flash window IFRAME
 **************************************************/
var WindowUtil = {
    version:'1.0.1',
    openWindow : function(uni) {
        var content = uni.split(",");
        
        if(bFlash) {
            $("Finder").style.zIndex=-1;
        }
        else {
            $("ctl00_ContentPlaceHolder_UniversityList").style.display = "none";
            $("UniversityIFrame").style.border = "1px solid silver";
        }
        University.getUniversity(content[0], content[1]);
    },
    
    closeWindow : function() {
        try {
            var uc = this.getParentElement("UniversityContent");
            var uif = this.getParentElement("UniversityIFrame");
            if(bFlash) {
                
                var finder = this.getParentElement("Finder");
                
                finder.hide();
                finder.style.visibility = "visible";
            }
            else {
                this.getParentElement("ctl00_ContentPlaceHolder_UniversityList").style.display = "";
            }
           
            uc.style.display = "none";        
            uif.src = "about:blank";
        }
        catch(e) {
            alert(" 11 closeWindow: " + e);
        }
        
        return false;  
    },
    
    getParentElement : function(id) {
        return window.parent.document.getElementById(id);
    },
    mouseOver : function(obj, src) {
        if(obj != _activeVideo) 
            this.setImageNode(obj,src);
    },
    mouseOut : function(obj, src) {
        this.setImageNode(obj,src);
    },
    setImageNode : function(obj, src) {
        for(var i=0;i<obj.childNodes.length;i++) {
            if(obj.childNodes[i].nodeName.toUpperCase() == "IMG")
            {
                obj.childNodes[i].src = src;
                break;
            }
        }
    }
    
    
};

function show(uni) {
    if(uni.length==0) { 
        WindowUtil.closeWindow();
        return false;
    }
    WindowUtil.openWindow(uni); 
}

/* Video Player
 **************************************************/
 var _activeVideo = null;
 
 var VideoUtil = {
    flash : bFlash,
    clips : null,
    clipIdx : -1,
    playClip : function(src) {


        if(!this.flash) return;
        _activeVideo = null;
        // get clip index from src //
        if( src != undefined ){

            for( var i=0;i<this.clips.length;i++ ){
                var hrf = document.getElementById(this.clips[i]);
                
                hrf.onmouseout();
                if( this.clips[i] == src ){
                    this.clipIdx = i;
                    hrf.onmouseover();
                    _activeVideo = hrf;
                }
            }
        } else {
            // normalise idx //
            if(this.clipIdx < 0) this.clipIdx = this.clips.length-1;
	        if(this.clipIdx >= this.clips.length) this.clipIdx = 0;
	        src = this.clips[ this.clipIdx ];
	        var hrf = document.getElementById(src);
	        if(hrf!=null) {
	            hrf.onmouseover();
	            _activeVideo = hrf;
	        }
	        //Remove the mouse over from clips that aren't playing
	        for(var i=0;i<this.clipIdx;i++)
	        {
	            hrf = document.getElementById(this.clips[i]);
                hrf.onmouseout();
	        }
	        
	        
        }
        
        var swf = document.getElementById( "FlashPlayerControl" );
        swf.loadFLV( src );
    
    }
 
 }
	
function getNextClip(){
    next();
}

function next(){
    VideoUtil.clipIdx++;
    VideoUtil.playClip();
}

function prev(){
	VideoUtil.clipIdx--;
	VideoUtil.playClip();
}

function playClip(src) {
    VideoUtil.playClip(src);
}

/********************************COOKIE METHODS********************************/

var d = new Date();
d.setTime(d.getTime()+(24*60*60*1000)); // remove 180 days. Now just 24 hours
var CookieExpiryDate = d.toGMTString();

function ReadCookie (name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function WriteCookie (name,value,date)
{
	document.cookie = name+"="+value+"; expires="+date+"; path=/";
}

/* Google MAPS
 **************************************************/

var MapUtil = {
    version: '1.0.0',
    googleMap : null,
    loaded : false,
    markers : null,
    createdMarkers : new Array(),
    pointers : new Array(),
    captions : null,
    startLocation : null,
    initializeMap : function () {
      if (GBrowserIsCompatible()) {
      
        try {
              var point =  this.startLocation;
              map = new GMap2(document.getElementById("map_canvas"));
              map.setCenter(point, 12, G_NORMAL_MAP);
              
              map.addControl(new GMapTypeControl());
              map.addControl(new GSmallMapControl());
              
              this.googleMap = map;
              this.addMarker(markers[0], this.captions[0]);

              this.loaded = true;
        }
        catch(e) {
            alert("initializemap: " + e);
        }
     }
   },
   createMarker : function (map, point, caption) {
      var marker = new GMarker(point);
      marker.value = caption;
      GEvent.addListener(marker, "click", function() {
        var myHtml = "<b>" + caption + "</b>";
        map.openInfoWindowHtml(point, myHtml);
      });
      return marker;
    },
   markerClick : function(marker, point) {
        try {
            marker.openInfoWindowHtml("Marker #<b>" + marker.caption + "</b>");
        }catch(e){}
   },
   setCenter: function(info, point) {
        this.addMarker(point,info);     
        this.googleMap.setCenter(point, 12, G_NORMAL_MAP);
        return false;
   },
   getCenter: function() {
        var center =  this.googleMap.getCenter();
        var coords = center.lat() + "," + center.lng();
        return coords;
   },
   addMarker : function(point, caption) {
        var marker = this.createMarker(this.googleMap,point,caption);
        
        var found = false;
        for(var i=0;i<this.createdMarkers.length;i++)
        {
            this.createdMarkers[i].hide();
            if(marker==this.createdMarkers[i])
            {
                found = true;
                this.createdMarkers[i].show();
                break;
            }
        }
        
        if(!found)
        {
            this.createdMarkers.push(marker);
            this.googleMap.addOverlay(marker);
        }
   },
   mapOnChange : function(obj) {
    var index = obj.selectedIndex;
    var map = obj[index].value;
    if(map.length<0) return false;
    return eval(map);
   },
       
  /*GEvent.addListener(marker, "click", function() {
   marker.openInfoWindowHtml(name);
  });*/

    loadMapSearchControl : function(location) {
          var options = {
            zoomControl : GSmapSearchControl.ZOOM_CONTROL_ENABLE_ALL,
            title : "GlobalBeach",
            url : "http://www.google.com/corporate/index.html",
            idleMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM,
            activeMapZoom : GSmapSearchControl.ACTIVE_MAP_ZOOM
           }

            new GSmapSearchControl(
                                $("mapsearch"),
                                locaction,
                                options
            );
    }
      
};
/*
// arrange for this function to be called during body.onload
// event processing
//GSearch.setOnLoadCallback(LoadMapSearchControl);
*/


