
var jQ = jQuery.noConflict(), 
	HandleVideoComplete, 
	suspendOut = false, 
	autoPlayFirst = false;

function GetPortalUserCookie(name) {  
  var cname = name + "=";               
  var dc = document.cookie;             
  if (dc.length > 0) {              
    begin = dc.indexOf(cname);       
    if (begin != -1) {           
      begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    } 
  }
  return null;
} // end GetCapellaCookiefunction
var signOnCookie = GetPortalUserCookie("SignOnDefault");
var CapUcookie = GetPortalUserCookie("CapellaUniversity");
var iGuideCookie = GetPortalUserCookie("iG3user");
var strHost = window.location.href.toLowerCase();
var strHost = strHost.replace('http://', '');
var strHost = strHost.substring(0,8)
//alert(strHost);
CapUcookie = (CapUcookie == null)? "" : CapUcookie;
if ((strHost == "devvcweb") || (strHost == "stgvcweb") || (strHost == "qlavcweb") || (strHost == "qavcweb")){
	var trackingSuiteConfigured = "capelladev";  
} else {
	if (signOnCookie != null || CapUcookie.toLowerCase().indexOf("portaluser=true") > -1 || iGuideCookie != null) {
		//any of the above conditions means the person has iGuide or Stella accesss
		var trackingSuiteConfigured = "capellamedia,capellaprod,capellavc,capellavcportalusers";
	} else {
		var trackingSuiteConfigured = "capellamedia,capellaprod,capellavc,capellavcprospects";
	}
}


// in order to use the '$' within the .ready function, pass it jQuery aliased as '$'...
jQuery(document).ready(function($){
	var videoURL = "http://video.capellavideo.com/nonCourse/VisitorCenter/homepage480/",
		//mTrackingSuite = "'capellamedia,capellaprod,capellavc,capellavcprospects,capellavcportalusers,capelladev'",
		mTrackingSuite = trackingSuiteConfigured,
		mTrackingPlayerName = "Visitor Center | VideoPlayer", 
		CURRENT_ELEMENT, 
		count = 0;
				
	function SetVideo(el){
		$('#vcVideoContainer', el).css({'display':'block'});
		
		var meta = $(el).metadata(), 
			mTitle = "Visitor Center | VideoPlayer | " + meta.vidTitle, 
			videoSource = meta.videoSource, 
			flashWidth = '480', //This size is unique, but it plays a 448px vid
			flashHeight = '295', //252 + 25px player
			flashVersion = '9.0.0',
			expressInstall = '/JavaScript/swfObject/2.1/expressInstall.swf',
			flashvars = {
				trackingTitle: mTitle,
				trackingPlayerName: mTrackingPlayerName,
				trackingSuite: mTrackingSuite,   
				URL: videoURL,
				source: videoSource,
				source112: videoSource,
				source256: videoSource,
				source512: videoSource
			}, 
			params = {
				menu: "false", 
				allowScriptAccess: "always",
				SeamlessTabbing: "false",
				swLiveConnect: "true"
			}, 
			attributes = {
				id: "vcVideoContainer", 
				name: "vcVideoContainer"
			};

		swfobject.embedSWF(
			'http://www.capella.edu/video/otherPlayers/CVP2_480_295_Switcher_Commercials.swf', 
			'vcVideoContainer', 
			parseInt(flashWidth), 
			parseInt(flashHeight), 
			String(flashVersion), 
			String(expressInstall), 
			flashvars, 
			params, 
			attributes
		); 
		
		$("#transcriptHolder .transcript").attr({
			href: "javascript:void(window.open('" + meta.transcriptURL + "','newWin','menubar=0,toolbar=0,location=0,status=0,width=480,height=380,resizable=1,scrollbars=1'))",
			style: "display:block;"
		});
	}

// I am not sure what these functions are used for (if at all). 
// I am commenting them out until it becomes apparent that it broke something...
/*
	function GetFlashMovie(movieName){
		var isIE = navigator.appName.indexOf("Microsoft") != -1;
		return (isIE) ? window[movieName] : document[movieName];
	}
	
	function PlayVideo(){
		GetFlashMovie("vcVideoContainer").flashStartMedia();
	}
*/
	HandleVideoComplete = function(){
		$("#transcriptHolder .transcript").removeAttr("href").removeAttr("style");
		suspendOut = false;
		$('#vcMedia').cycle('resume');
	};
	var cycleTimeOut = 4000, 
		cycleSpeed = 1000;
	
	$('#vcMedia').cycle({
		fx: 'fade',
		speed:  cycleSpeed, 
		timeout: cycleTimeOut,
		pause: 0,
		prev: '#vcPrev',
		next: '#vcNext',
		pager: '#nav',
		before: function() {
			var $this = $(this), 
				meta = $this.metadata(), 
				poster = $('.poster', $this), 
				icon = poster.find('span');
				
			if (CURRENT_ELEMENT) {
				$('#vcVideoContainer', CURRENT_ELEMENT).remove();
				$('.poster', CURRENT_ELEMENT).unbind('click');
				$("#transcriptHolder .transcript").removeAttr("href").removeAttr("style");
				$('#vcMedia').cycle('resume');
			}
			
			
			$(this).append("<div id='vcVideoContainer'>You must have flash 9.0 or greater</div>");
			if(meta.media === 'video'){
				poster.attr('title', 'Click here to play');
				icon.addClass('playbutton');
			}else{
				poster.attr({
					'title': 'Click here to read more',
					'href':  meta.href
					//'href': 'javascript:void(window.open("' + meta.href + '", "newWin", "menubar=0,toolbar=1,location=0,status=0,width=1040,height=600,resizable=1,scrollbars=1"))'
				});
				icon.addClass('hyperlink');
			}
			poster.css({'display': 'block'});
			
			CURRENT_ELEMENT = this;
			
			if(autoPlayFirst == true){
				$('.poster', $(this)).css({'display':'none'});
				$('#vcMedia').cycle('pause');
				SetVideo(CURRENT_ELEMENT);
				autoPlayFirst = false;
			}else{
				$('.poster', $(this)).bind('click', function(){
					$('#vcMedia').cycle('pause');
						var s=s_gi(s_account); //omniture tracking addition
        				s.tl(this,'o','Cycler-'+meta.linkText+''); //omniture tracking addition
					if(meta.media === 'video'){
						suspendOut = true;
						$(this).fadeOut(1000, function() {
							SetVideo(CURRENT_ELEMENT);
						});
					}
				});
			}
		},
		after: function(){},
		pagerAnchorBuilder: function(idx, slide) { 
			var meta = $(slide).metadata();
				if(meta.media === 'video'){ 
					return '<li class="vcBtn '+ meta.thumbnail +'" id="'+ meta.thumbnail +'"><span class="visualTrigger"><span class="displace">'+meta.linkText+'</span></span><a href="#'+ meta.thumbnail +'" class="visuallyhidden" title="use this link to play the video inside the '+meta.linkText+' dynamic content area">'+meta.linkText+'</a></li>'; 
				} else {
					return '<li class="vcBtn '+ meta.thumbnail +'" id="'+ meta.thumbnail +'"><span class="visualTrigger"><span class="displace">'+meta.linkText+'</span></span><a href="#'+ meta.thumbnail +'" class="visuallyhidden" title="use this link to open a new page and read more about '+meta.linkText+'">'+meta.linkText+'</a></li>'; 
				}
		},
		updateActivePagerLink: function(navId, idx, className){
			var selector = navId + ' li:eq('+idx+')';
			$('.vcBtn').removeClass(className);
			return $(selector).addClass(className); 
		}
	});

	$('a.poster').mouseout(function(){
		if (!suspendOut){
			$('#vcMedia').cycle('resume');
		}
	}).mouseover(function(){
		$('#vcMedia').cycle('pause');
	});           
	
	$('.vcBtn').each(function(){
		count++;
		var meta = $(this).metadata();
	});

//Accessibility Additions - start	
	$('.visuallyhidden').bind('click', function(){
				var panelSelector = $(this).parent().prevAll().length + 1;		
				var meta = $('#item'+panelSelector+'').metadata();
			if(meta.media === 'video'){
				$(this).parent().click();
				$('#item'+panelSelector+' a').trigger('click');
				$('#transcriptHolder a').focus();
			} else {
				//window.open("" + meta.href + "", "newWin")
			}
	});

	$('.visuallyhidden').focus( function(){
	$('#vcMedia').cycle('pause');
			var panelSelector = $(this).parent().prevAll().length + 1;		
			var meta = $('#item'+panelSelector+'').metadata();
			var panelName = '#item'+panelSelector+'';
			$(this).parent().click();
			//$('.poster').css({'display': 'none'});
			//$(''+panelName+'').css({'display': 'block', 'opacity' : '1', 'z-index': '6', 'filter' : 'alpha(opacity=0)'});
			//$(''+panelName+' a.poster').css({'display': 'block'});
				//if(meta.media === 'video'){
					//$(''+panelName+' .poster span').addClass('playbutton');
				//} else {
					//$(''+panelName+' .poster span').addClass('hyperlink');
				//}
			$('#vcNav li').removeClass('activeSlide');
			$(this).parent('li').addClass('activeSlide');	
	}).blur(function(){
			$(this).parent('li').removeClass('activeSlide');	
			var panelSelector = $(this).parent().prevAll().length + 1;		
			var meta = $('#item'+panelSelector+'').metadata();
				if(meta.media === 'video'){
					$("#transcriptHolder .transcript").removeAttr("href").removeAttr("style");
					$('#vcVideoContainer').remove();
				}
	});
//Accessibility Additions - end	
jQuery('#item1 a.poster').attr('href', '/tuition_financial_aid/back_to_school.aspx');
jQuery('#item4 a.poster, #item5 a.poster').attr('target', '_blank');
});


