$(document).ready(function() {
	$("a.tooltip").tipTip({delay:0});
	$("a.tooltip-footer").tipTip({delay:0, defaultPosition:"right",edgeOffset:10});
	$(".img-dot").tipTip({edgeOffset:5});
	$('a.tooltip').click(function() {
    	$('.video-bar').animate({ top: "241px"}, 800);
    	$('.video-close-btn').hide();
    	slideOpen = false;
    	var vidDiv = $(this).attr('href').replace('#','');
    	$('div.panel').hide();
    	$('div#' + vidDiv).show();
    	return false;
    });

	$('.searchBox').focus(function(){  
		if($(this).attr('value') == 'search') $(this).attr('value', '');
	});
	var vidCount =  $('#vid-thumbs-slider a.tooltip').size(); 
	var vidCountRight = vidCount - 3;
	var vidCountLeft = 0;
	var totalWidth = vidCount * 150;
    var vidAnimate = 0;
    $('.playerthumb_left').append('<p>' + vidCountLeft + '</p>');
    $('.playerthumb_right').append('<p>' + vidCountRight + '</p>');
    
    $('.playerthumb_left').click(function(){
    	 if (vidAnimate != 0) {	
   			vidAnimate = vidAnimate + 150;
            $('#vid-thumbs-slider').animate({left: vidAnimate + 'px'});
         }
         if (vidCountLeft > 0) {
        	$('.playerthumb_right').html('').append('<p>' + (vidCountRight + 1) + '</p>');
        	$('.playerthumb_left').html('').append('<p>' + (vidCountLeft - 1) + '</p>');
        	vidCountLeft--;
        	vidCountRight++;
        }
         return false;
    });
    $('.playerthumb_right').click(function(){
        if (Math.abs(vidAnimate) < totalWidth - 450) {	
         	vidAnimate = vidAnimate - 150;
        	$('#vid-thumbs-slider').animate({left: vidAnimate + 'px'});
        }
         if (vidCountRight > 0) {
        	$('.playerthumb_right').html('').append('<p>' + (vidCountRight - 1) + '</p>');
        	$('.playerthumb_left').html('').append('<p>' + (vidCountLeft + 1) + '</p>');
        	vidCountLeft++;
        	vidCountRight--;
        }
        return false;
    });
     
     
	$('.searchBox').blur(function(){  
		if($(this).attr('value') == '') $(this).attr('value', 'search');  
	});
	$('.searchBox').click(function(){
		$(this).select();
	});  

	$('#info-side-closed').click(function(){
		$(this).removeAttr('id', 'info-side-closed');
		$(this).attr('id','info-side-open');
		$('#info-side-open').animate({ width: '560px' });
	});
	$('#info-side-open-close').click(function(){
		$('#info-side-open').css({ width: '41px' });
		$('#info-side-open').attr('id','info-side-closed');
		$('#info-side-open').removeAttr('id','info-side-open');

	});
	$('#container').click(function(){
		$('#info-side-open').css({ width: '41px' });
		$('#info-side-open').attr('id','info-side-closed');
		$('#info-side-open').removeAttr('id','info-side-open');
	});
	
	$('.classpagesbtn').click(function(){
		$('#events').hide();
		$('#classpages').show();
		$('#homecoming').hide();
		return false;
	});
	
	$('.homecomingbtn').click(function(){
		$('#events').hide();
		$('#homecoming').show();
		$('#classpages').hide();
		return false;
	});
	
	$('.sm-slide-down').hide();	
	var imgRoot = 'http://www.cord.edu/images/template/sm_box/';
	var imgUp = 'sm_up_arrow.jpg';
	var imgDown = 'sm_down_arrow.jpg';
	
	$('a.sm-more').click(function() {	
		var smBoxRoot = $(this).parent().parent('.sm-box');	
		var slideDownRoot = $(smBoxRoot).find('.sm-slide-down');
		if ($(slideDownRoot).css('display') == 'none') {
			$(slideDownRoot).slideDown(500, function(){
				$(smBoxRoot).find('.sm-up-down-arrow').attr('src', imgRoot + imgUp);
			});
		}
		else {
			$(slideDownRoot).slideUp(500, function(){
				$(smBoxRoot).find('.sm-up-down-arrow').attr('src', imgRoot + imgDown);
			});
		}
			
		return false;
	});
	
	var slideOpen = false;
	$('.video-info-btn').click(function() {
		
        if(slideOpen == false) {
       		$(this).parents('.video-bar').animate({ top: "20px"}, 1000);
       		$('.video-close-btn').show();
   	    	slideOpen = true;
   	    	return false;
        } else {
       		$(this).parents('.video-bar').animate({ top: "241px"}, 1000);
       		$('.video-close-btn').hide();
       	 	slideOpen = false;
       	 	return false;
        }
    });
 	$('.video-close-btn').click(function() {
 		$('.video-bar').animate({ top: "241px"}, 800);
 		$('.video-close-btn').hide();
       	slideOpen = false;
       	return false;
 	});
	
	$('#call-to-action-majors').hover(function(){
		$(this).stop().animate({ left: '0' });
		$('#call-to-action-visit').stop().animate({ left: '0' });	
	},
	function(){
		resetAnimation();
	});
		$('#call-to-action-visit').hover(function(){
		$(this).stop().animate({ left: '0' });
		$('#call-to-action-majors').stop().animate({ left: '-348px' });	
	},
	function(){
		resetAnimation();
	});
		$('#call-to-action-tour').hover(function(){
		$('#call-to-action-majors').stop().animate({ left: '-348px' });	
		$('#call-to-action-visit').stop().animate({ left: '-347px' });
	},
	function(){
		resetAnimation();
	});
	function resetAnimation() {
		$('#call-to-action-majors').stop().animate({ left: '-220px' });	
		$('#call-to-action-visit').stop().animate({ left: '-110px' });	
		$('#call-to-action-tour').stop().animate({ left: '-0px' });
	}
	
	$('#chapter-bg div').hover(function() {
		$(this).addClass('chapter-hover');
		$(this).find('p').css('color','#666666');
		$(this).find('.ch-box-overlay').clone().appendTo('#chapter-bg').fadeIn(300);
	},
	function() {
		$(this).removeClass('chapter-hover');
		$(this).find('p').removeAttr('style');
		$('.ch-box-overlay').fadeOut(300);
	});
	$('#chapter-bg div').click(
	function() {
	    window.location = $(this).attr('rel');
    	return false;
	});
	$('.adm-rep-visit-person').hover(function() {
		if($(this).find('.adm_travel_collapse').css("display") == "none") {
			$(this).find('h2').append('<img class="down-arrow-travel-page" src="http://www.cord.edu/images/template/admissions/travel_schedule.jpg"/>');
			$('.down-arrow-travel-page').fadeIn(500);
		}
	},
	function() {
		$(this).find('.down-arrow-travel-page').remove();
	});
	
	$('.adm-rep-visit-person h2').click(function(){
		$('.down-arrow-travel-page').css({display:'none'});
		$('.adm_travel_collapse').css({display: 'none'});
		$('.adm-rep-visit-person').css({background:'#efefef'});	
		$(this).parent('.adm-rep-visit-person').css({background:'#d6e0e9'}).find('.adm_travel_collapse').toggle(300);
	});
	   

    
});
$(window).load(function() {
	var chapterImgWidth = $('#spiffBanner img').width();
	if (chapterImgWidth<250 && $('#spiffBanner').not('.rightImage')) {$('#spiffBanner').addClass('leftImage');}
    $('#spiffBanner').css({width: chapterImgWidth});
});

function thisMovie(movieName) {
if(navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
return document[movieName];
}
};
var player;
var playerName;
function playerReady(obj)
{
player = gid(obj.id);
player.addModelListener('STATE', 'stateMonitor');
};

function stateMonitor(obj)
{
if((obj.newstate == 'COMPLETED') && ((obj['id']) =="videoContent"))
{
// drop out of fullscreen
this.window.focus();
// load buttons
document.getElementById('flashcontentOver').style.display = 'block';
document.getElementById('videoContent').sendEvent('STOP');
}
};
function stopPlayer () {
	document.getElementById('videoContent').sendEvent('STOP');
};

function gid(name)
{
return document.getElementById(name);
};

function resetVideo()
{
document.getElementById('flashcontentOver').style.display = 'none';
document.getElementById('videoContent').sendEvent('PLAY', 'true');
}


function searchNow(){
        //Determine the search term
        var searchFor=document.getElementById('txtSearchTerm').value;
        //Write out the url
        //<! [CDATA[
        document.location.href="http://www.cord.edu/search/?q="+searchFor+"&site=default_collection&client=concordia&output=xml_no_dtd&proxystylesheet=concordia";
        //]]-->
}
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
	return vars;
}


