//Globals
var startDate = ''
var endDate = ''
var calendarMode = 'Grid'

function checkvalue(val){
		if (val.indexOf('$')>-1 || val.indexOf('.')>-1){
			alert('Enter only numbers; no dollar signs or commas. Enter only rounded dollar amounts (100, not 100.50).');
			}
	}

//SWITCH NAV
function loadevents(link,wrapper,mode){   
    $('calendarindicator').style.display = 'block';

    if (link.indexOf('=')>-1){
        var linkpair = link.split('=');
        startDate = linkpair[1];      
    } else {
        if (mode=='Grid'){
            link += '?date=' + startDate;
        } else {
            link += '?startdate=' + startDate;
        }
    };

    calendarMode = mode;
    if(calendarMode=='List'){
        $('gridlink').style.color = '#342E2E';
        $('listlink').style.color = '#e9376b';
        $('listlink').style.fontWeight = 'bold';
	    $('gridlink').style.fontWeight = 'normal';
        $('gridlink').onmouseover  = function(){
            if($('gridlink').style.color == 'rgb(52, 46, 46)'){
                $('gridlink').style.color = '#e9376b';
	        }
	    }
	    $('gridlink').onmouseout  = function(){ 
            if($('gridlink').style.fontWeight != 'bold'){
                $('gridlink').style.color = '#342E2E';
	        }
	    }
    } else {
        $('gridlink').style.color = '#e9376b';
        $('listlink').style.color = '#342E2E'; 
        $('listlink').style.fontWeight = 'normal';
	    $('gridlink').style.fontWeight = 'bold';
        $('listlink').onmouseover  = function(){
            if($('listlink').style.color == 'rgb(52, 46, 46)'){
                $('listlink').style.color = '#e9376b';
	        }
	    }
	    $('listlink').onmouseout  = function(){ 
            if($('listlink').style.fontWeight != 'bold'){
                $('listlink').style.color = '#342E2E';
	        }
	    }
    }
    
    new Ajax.Request(link, {
	method: "get",
	onComplete: function(transport) { 
	    $('calendarindicator').style.display = 'none';
		$(wrapper).innerHTML = transport.responseText;
		InitializeToolTips();
		hoverdates();
		CheckEventIcons();
	
		}//-onSuccess
		}//-request arguments
		);// new ajax request	
}

function ToggleEventIcon(eventtypeid) {
    var x=document.getElementsByTagName("img");
	var handle = 'left gridicon1 eventtypeimg'
	for (var i=0;i<x.length;i++){
		if (x[i].className.indexOf(handle)>-1){	
            if (x[i].className.replace(handle,'') == eventtypeid){
               if ($(x[i].id).style.display == 'block') {
                    $(x[i].id).style.display = "none";
                } else {
                    $(x[i].id).style.display = "block";
                }
            }
		}
	}
}

function CheckEventIcons(){
    for(i=0; i<document.forms.legend.elements.length; i++){
        var x = document.forms.legend.elements[i];
        if(x.type=="checkbox"){
            if (x.checked){
                TurnEventIcon(x.name.replace('toggle',''),'on')
            } else {
                TurnEventIcon(x.name.replace('toggle',''),'off')
            }
        }
    }
}

function TurnEventIcon(eventtypeid,onoroff) {
    var x=document.getElementsByTagName("img");
	var handle = 'left gridicon1 eventtypeimg'
	for (var i=0;i<x.length;i++){
		if (x[i].className.indexOf(handle)>-1){	
            if (x[i].className.replace(handle,'') == eventtypeid){
               if (onoroff=='off'){
                    $(x[i].id).style.display = "none";
                } else {
                    $(x[i].id).style.display = "block";
                }
                
            }
		}
	}
}
    
//VALIDATION
function createaccount(formname,validateid,indicatorid,color1,color2) {
	//VALIDATE REQUIRED
	if(validateform(formname,color1,color2)){	 

	    document.forms[formname].__VIEWSTATE.name = 'NOVIEWSTATE';
	    document.forms[formname].__VIEWSTATE.id= 'NOVIEWSTATE';

		new Ajax.Request('sc_createnewaccount.ashx', {
		method: "post",
		parameters: Form.serialize(document.forms[formname]),
		onComplete: function(transport) {
		        var r = transport.responseText; 
		        if (!r.indexOf("KeepGoing")){
		            document.forms[formname].NOVIEWSTATE.name = '__VIEWSTATE';
		            document.forms[formname].NOVIEWSTATE.id = '__VIEWSTATE';
		            document.forms[formname].submit();
		        } else {
		            document.getElementById(indicatorid).style.display = "none";
		            document.getElementById(validateid).innerHTML = r;
                    formfieldbg(r,"Zip","billing_zip",color1,color2);
                    formfieldbg(r,"Email","billing_email",color1,color2);
                    formfieldbg(r,"Username","newuser",color1,color2);
                    formfieldbg(r,"Passwords","newpassword",color1,color2);
                    formfieldbg(r,"Passwords","newpassword2",color1,color2);	           
		            if (document.getElementById(validateid).style.display == "none"){
		                document.getElementById(validateid).style.display = "block";
		            } else {
		                Effect.Shake(validateid);
		            }
		        }
			}
		}
		);
	} else {
	    document.getElementById(validateid).innerHTML = 'Please fill in Required Fields.';
	    if (document.getElementById(validateid).style.display == "none"){
			Effect.Appear(validateid,'blind');
		} else {
			Effect.Shake(validateid);
		}
	}
}

function showmenu(themenu){
	if ($(themenu).style.display == "none"){
		$(themenu).style.display = "block"
	} else {
		$(themenu).style.display = "none"
	}
}

function loaddiv(divid,ajaxpage,tab,handle){
	//TABS
	var x=document.getElementsByTagName("img");
	for (var i=0;i<x.length;i++){
		if (x[i].id.indexOf(handle)>-1){
			var element = document.getElementById(x[i].id);
			if (element.id == tab){
				element.src = element.src.replace('/off/','/on/')
			} else {
				element.onmouseover = tabover;
				element.onclick = tabclick; 
				element.onmouseout = tabout; 
				element.src = element.src.replace('/on/','/off/')
			}
		}
	}
	
	//AJAX REQUEST
	new Ajax.Request(ajaxpage, {
	method: "get",
	onComplete: function(transport) { 
		document.getElementById(divid).innerHTML = transport.responseText;
		}//-onSuccess
		}//-request arguments
		);// new ajax request	
}

//TYPE OF PROBLEM
function problem(level,parentid){
    level += 1;
    var x=document.getElementsByTagName("div");
    var ii = 0
    var handle  = 'problem-name-' + level + '-' + parentid + '-'
	for (var i=0;i<x.length;i++){
	    if (x[i].id.indexOf(handle)>-1){
	        var element = document.getElementById(x[i].id);
			var theid = element.id.replace(handle,'');
			if (document.getElementById(handle + theid).style.display == 'block'){
			   	document.getElementById(handle + theid).style.display = 'none';
			} else {
			    document.getElementById(handle + theid).style.display = 'block';
			}	
	    }
	}
}

function spidermenus(triggerhandle,menuhandle){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++){
		if (x[i].id.indexOf(triggerhandle)>-1){
			//VARIABLES
			var element = document.getElementById(x[i].id);
			var theid = element.id.replace(triggerhandle,'');
            
			//TRIGGERS
			var thetrigger = document.getElementById(triggerhandle + theid);
			thetrigger.onmouseover = function() {  
			    this.style.position = 'relative';
				var menutoswitch;
				menutoswitch = this.id.replace('trigger','');
				
				document.getElementById(menutoswitch).style.display = "block";
				var navimg = this.id.replace('menutrigger','');
				document.getElementById('nav' + navimg).src = document.getElementById('nav' + navimg).src.replace('/off/','/roll/');
			    };
			thetrigger.onmouseout = function() {
			    this.style.position = 'static';
				var menutoswitch;
				menutoswitch = this.id.replace('trigger','');
				document.getElementById(menutoswitch).style.display = "none";
                var navimg = this.id.replace('menutrigger','');
                
				document.getElementById('nav' + navimg).src = document.getElementById('nav' + navimg).src.replace('/roll/','/off/');
			};
			
			//MENUS
			var themenu = document.getElementById(menuhandle + theid);
			themenu.onmouseover = function() {
				var menutoswitch;
				menutoswitch = this.id;
				document.getElementById(menutoswitch).style.display = "block";
				
			};
			themenu.onmouseout = function() {
				var menutoswitch;
				menutoswitch = this.id;
				document.getElementById(menutoswitch).style.display = "none";
			};
		} 
	}
}

//UPDATE CART
function updatecart(formname){
    new Ajax.Request('/sc_addtocart.ashx', {
	method: "post",
	parameters: Form.serialize(document.forms[formname]),
    onSuccess: function(transport) {
        var resp = transport.responseText.split("^");
	    document.getElementById("sc_minicart_subtotalwrapper").innerHTML = '$' + resp[1];
			}//-onSuccess
	    }//-request arguments
    );// new ajax request
}

//ADD TO CART
function addtoshoppingcart(formname,messageid){ 
    if(validateform(formname,'#f9f7cb','#f9f7cb')){	

        var Digital=new Date()
        var seconds=Digital.getSeconds()
        var hours=Digital.getHours()
        var minutes=Digital.getMinutes()
        new Ajax.Request('/sc_addtocart.ashx?refresh=' + seconds + hours + minutes, {
        method: "post",
        parameters: Form.serialize(document.forms[formname]),
        onSuccess: function(transport,formname) { 	
                document.getElementById(messageid).style.display = 'block';
                document.getElementById(messageid).innerHTML = 'Added!';
                var t = setTimeout("Effect.Fade('" + messageid + "');",1000);	
    	        
                //refreshcart('refreshcart');    
    	         
		        }//-onSuccess
            }//-request arguments
        );// new ajax request
        }
}

//MESSAGE
function message(messageid,message){
    document.getElementById(messageid).style.display = 'block';
    document.getElementById(messageid).innerHTML = message;
	var t = setTimeout("Effect.Fade('" + messageid + "');",1000);	
}

//REFRESH CART
function refreshcart(divid){
    var Digital=new Date()
    var seconds=Digital.getSeconds()
    var hours=Digital.getHours()
    var minutes=Digital.getMinutes()
    new Ajax.Request('/ajax/loadcart.aspx?refresh=' + new Date().getTime(), {
	    method: "get",
	    onSuccess: function(transport) { 
		    document.getElementById(divid).innerHTML = transport.responseText;
		    }//-onSuccess
		    }//-request arguments
		    );// new ajax request
}

//DELETE FROM CART
function remitem(cartrow,cartitemid){
	Effect.Fade(cartrow);
	
	//AJAX POST
	new Ajax.Request('/sc_deletecartitem.ashx?id=' + cartitemid, {
	method: "get",
	onComplete: function(transport) { 
        var resp = transport.responseText.split("^");
	    document.getElementById("ctl04_subtotalwrapper").innerHTML = '$' + resp[1];
	    //alert('test');
		}//-onSuccess
		}//-request arguments
		);// new ajax request
}


//VALIDATION
function validEmail(email) {
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return re.test(email); 
}
		
//VALIDATION
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
		
//VALIDATION
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
		
//VALIDATION
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
		
//VALIDATION
function isFilled(elm) {
	//alert(elm.type);
	//Last Updated by Sol - 6/14/07
	switch(elm.type){
	case "text":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "password":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "textarea":
		if (trim(elm.value) == "" || elm.value == null){
		return false;}
		else {return true;}
		break;
	case "select-one":
		var myindex=elm.selectedIndex;
		if (myindex==0){
		return false;}
		else {return true;}
		break;
	}
}

//VALIDATION
function validateform(formname,color1,color2){
	//last updated on 9/27/07
	//index of is mo betta

	var x = document.forms[formname];
	var allgood = true;
	for (var i=0;i<x.length;i++){
		if (x.elements[i].className.indexOf('required')>-1) {
		 	var thisformname = x.elements[i].name;
			var thisformid = x.elements[i].id;
			if (!isFilled(x.elements[i])) {
				document.getElementById(thisformid).style.background = color1;
				allgood = false;
				} else {
				  document.getElementById(thisformid).style.background = color2; 
				}
			}
		}
		if (allgood) {
			return true;
			} else {
			return false;
			}
	}
	
function spiderform(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'#f9f7cb','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var email = document.getElementById("email").value;
		if(!validEmail(email)){
			document.getElementById("email").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'appear');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {		
			document.getElementById(successid).innerHTML = transport.responseText;
			document.getElementById(indicatorid).style.display = "none";			
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	}
}

function spidersignup(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'#f9f7cb','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var email = document.getElementById("emailsignup").value;
		if(!validEmail(email)){
			document.getElementById("emailsignup").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'appear');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {	
			document.getElementById(indicatorid).style.display = "none";
			document.getElementById(successid).style.display = "block";	
			document.getElementById(successid).innerHTML = transport.responseText;	
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	}
}

function spiderfriend(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'#f9f7cb','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var friendemailfrom = document.getElementById("friendemailfrom").value;	
		var friendemailto = document.getElementById("friendemailto").value;

		if(!validEmail(friendemailfrom)){
			document.getElementById("friendemailfrom").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//alert('got here')
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {		
			document.getElementById(successid).innerHTML = transport.responseText;
			document.getElementById(indicatorid).style.display = "none";
				//alert(transport.responseText);			
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	}
}

function spiderbugreport(formname,validateid,successid,indicatorid,ajaxpage) {
	//VALIDATE REQUIRED
	if(validateform(formname,'#f9f7cb','#f9f7cb')){	
	
		//EMAIL IS VALID?
		var emailfrombug = document.getElementById("emailfrombug").value;
		var emailtobug = document.getElementById("emailtobug").value;
		//alert(emailfrombug);
		if(!validEmail(emailfrombug)){
			document.getElementById("emailfrombug").style.background = "white"; 
			document.getElementById(validateid).innerHTML = 'Invalid Email';
			if (document.getElementById(validateid).style.display == "none"){
					Effect.Appear(validateid,'blind');
					} else {
					Effect.Shake(validateid);
					}
			} else {
			document.getElementById(validateid).style.display = "none";
			document.getElementById(indicatorid).style.display = "block";
			//alert('got here')
			//AJAX POST
			new Ajax.Request(ajaxpage, {
			method: "post",
			parameters: Form.serialize(document.forms[formname]),
			onComplete: function(transport) {		
			document.getElementById(successid).innerHTML = transport.responseText;
			document.getElementById(indicatorid).style.display = "none";
				//alert(transport.responseText);			
				
				}//-onSuccess
			}//-request arguments
			);// new ajax request	
			
			//document.form.formname.submit();	
			}
	}
}

//IMAGE ROLLOVER
function rolloverInit(){
	for (var i=0; i<document.images.length; i++) {
	if (navigator.appName == "Netscape"){
		if (document.images[i].hasAttribute("name")){ 
				if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
					setupRollover(document.images[i]);
				}
		}
	} else
		if (document.images[i].getAttribute('name').indexOf("rollover")>-1){			
			setupRollover(document.images[i]);
		}
	}
}

//IMAGE ROLLOVER
//Last Update August 1, 2008
function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	//alert(thisImage.id);
	thisImage.outImage.id = thisImage.id;
	thisImage.onmouseout = rollOut;
	thisImage.overImage = new Image();
	thisImage.overImage.id = thisImage.id
	thisImage.overImage.src = thisImage.src.replace('/off/','/roll/')
	thisImage.onmouseover = rollOver;
}

//IMAGE ROLLOVER
function rollOver() {
	this.src = this.overImage.src;
}

//IMAGE ROLLOVER
function rollOut() {
	this.src = this.outImage.src;
}

function arrowtoggle(id){
    var arrow = document.getElementById(id);
    if(arrow.getAttribute('src').indexOf('off') >-1){
        document.getElementById(id).src = "/images/onarrow.gif";
    } else {
        document.getElementById(id).src = "/images/offarrow.gif";
    }
}

//SWITCH NAV
function loadgrid(){
    $('gridlink').style.color = '#e9376b';
    $('listlink').style.color = '#342E2E';
    new Ajax.Request('/ajax/grid.aspx', {
	method: "get",
	onComplete: function(transport) { 
		$('upcomingajaxwrapper').innerHTML = transport.responseText;
	    //scroll();
		InitializeToolTips();
		}//-onSuccess
		}//-request arguments
		);// new ajax request	
}

//SWITCH NAV
function loadlist(){
    $('gridlink').style.color = '#342E2E';
    $('listlink').style.color = '#e9376b';
    new Ajax.Request('/ajax/list.aspx', {
	method: "get",
	onComplete: function(transport) { 
		$('upcomingajaxwrapper').innerHTML = transport.responseText;
		scroll();
		}//-onSuccess
		}//-request arguments
		);// new ajax request	
} // 'upcomingajaxwrapper'


//SCROLL
function scroll(){
    //PROPERTIES
    
//    this.height = 1500;
//    this.increment = 20;
//    var me = this;

    //CHO, had to add if statement because only works in the scrolldown has loaded from ajax. also added     scroll(); to bottom of home page, not master loader;
    //let's not use ajax.
    
    if($('scrolldown')){
        //CHO, need to add "var" 
        //before events so that scope still exists.
        
        var clear;
      
        $('scrolldown').onmouseover = function() {
         
            clear = setInterval('scrolldown()',50);
        }
        $('scrolldown').onmouseout = function() { 
            
            clearInterval(clear);
        }
    }
   
    if ($('scrollup')){
       var clear1;
       $('scrollup').onmouseover = function() {
          
            clear1 = setInterval('scrollup()',50);
        }
        $('scrollup').onmouseout = function() {
            clearInterval(clear1);
        }
    }
}

function scrolldown(){
    //alert(findPosY($('position')));
    var y = findPos(document.getElementById('position'));
    var yzero = findPos(document.getElementById('positionzero'));
    //alert(y);
    //alert(yzero);
    var totalheight = y - yzero - 390;
    
    //alert(-totalheight);
    
    this.height = 1500;
    this.increment = 10;
    var me = this;
    var height = $('listcontainer').style.top;
    
    //alert(height);
    
    if (parseInt(height) >= -totalheight){
        var top = $('listcontainer').style.top;
        $('listcontainer').style.top = parseInt(top) - me.increment + 'px';
        $('scrollup').style.display = 'block';
        
    }
    else{
        $('scrolldown').style.display = 'none';
    }
}

function findPos(obj) {
	var curleft = curtop = 0;
        if (obj.offsetParent) {
            do {
			    curleft += obj.offsetLeft;
			    curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
        return [curtop];
    }
}

function scrollup(){
    this.height = 1500;
    this.increment = 10;
    var me = this;
    var height = $('listcontainer').style.top;
    if (parseInt(height) <= -1){
        var top = $('listcontainer').style.top;
        $('listcontainer').style.top = parseInt(top) + me.increment + 'px';
        $('scrolldown').style.display = 'block';
    }
    else{
        $('scrollup').style.display = 'none';
    }
}


//TWEEN

function tween1(){
	dummy_mc = document.getElementById('upcomingajaxwrapper');
    $('tweenlink').style.color = '#342E2E'
    $('tweenlink').onmouseover  = function(){
        if($('tweenlink').style.color == 'rgb(52, 46, 46)'){
            $('tweenlink').style.color = '#e9376b';
	    }
	}
	$('tweenlink').onmouseout  = function(){ 
        if($('tweenlink').style.fontWeight != 'bold'){
            $('tweenlink').style.color = '#342E2E';
	    }
	}
	$('tweenlink').onclick = function(){ 
	    moveSquare();
	    $('tweenlink').style.color = '#E9376B';
	    $('tweenlink').style.fontWeight = 'bold';
	    $('listlink').style.fontWeight = 'normal';
	    $('listlink').style.color = '#342E2E';
	}
	zz = new Tween(dummy_mc.style,'left','',parseInt(dummy_mc.style.left),10,1,'px');
}

function moveSquare(evt){
	if(!evt) evt = window.event;
	var duration = .7;
	var easingFunc = Tween.strongEaseOut;
	isNaN(duration) ? duration = 1 : null;
	zz.func = easingFunc;
	zz.continueTo(-450,duration);
}

function tween2(){
	dummy_mc = document.getElementById('upcomingajaxwrapper');
	$('listlink').onmouseover  = function(){ 
        if($('listlink').style.color == 'rgb(52, 46, 46)'){
            $('listlink').style.color = '#e9376b';
	    }
	}
	$('listlink').onmouseout  = function(){ 
        if($('listlink').style.fontWeight != 'bold'){
            $('listlink').style.color = '#342E2E';
	    }
	}
	$('listlink').onclick = function(){ 
	    moveSquare2();
	    $('listlink').style.color = '#E9376B';
	    $('tweenlink').style.color = '#342E2E';
	    $('listlink').style.fontWeight = 'bold';
	    $('tweenlink').style.fontWeight = 'normal';
	}
	zz = new Tween(dummy_mc.style,'left','',parseInt(dummy_mc.style.left),10,1,'px');
}

function moveSquare2(evt){
	if(!evt) evt = window.event;
	var duration = .7;
	var easingFunc = Tween.strongEaseOut;
	isNaN(duration) ? duration = 1 : null;
	zz.func = easingFunc;
	zz.continueTo(0,duration);
}

//END TWEEN

function scroll1(){
    setInterval('scrollright()',50);
}

function scrollright(){
    var width = 100;
    this.increment = 100;
    var me = this;
    var left = $('upcomingajaxwrapper').style.left;
    if (parseInt(left) >= -430){
        //var top = $('listcontainer').style.top;
        $('upcomingajaxwrapper').style.left = parseInt(left) - me.increment + 'px';
        //$('scrolldown').style.display = 'block';
    }
    else{
        //$('scrollup').style.display = 'none';
    }
}

//SLIDE
function SlidesShow(){
    //PROPERTIES
    this.slideTotal = 0;
    this.slideContainer = ''; //ID NAME
    this.slideWrapper = '';//ID NAME
    this.nextButton = ''; //ID OF HREF(SO THAT ELEMENT CAN BE TEXT OR IMAGE)
    this.prevButton = '';
    this.slideIncrement = 15; //SLIDE INCREMENTS
    this.slideHeight = 350; // WIDTH OF EACH DIV OR IMAGE
    this.next = nextSlide;
    this.previous = prevSlide;
    this.nextUrl = '';
    this.prevUrl = '';
  
    //VARIABLES
    var loopI = 0; //KEEPS TRACK OF EACH slideIncrement FROM 0 TO slideHeight, 50, 100, 150, 200
    var goNext = null;
    var goBack = null;
    var me = this;
    
    function setProperties(){
          me.prevUrl = document.getElementById(me.prevButton).style.href;
          me.nextUrl = document.getElementById(me.nextButton).style.href;
    }
    
    //METHODS
    function nextSlide(){  
	    document.getElementById(me.prevButton).style.display = "block";
	    goNext = setInterval(nextSlideDetail,1);
    }
    
    function prevSlide(){
	    goBack = setInterval(prevSlideDetail,1);
    }
    
    function nextSlideDetail(slideEnd,nextUrl){
        document.getElementById(me.nextButton).removeAttribute("href");  
	    var slideStart = parseFloat(document.getElementById(me.slideContainer).style.top);
	    slideEnd = slideStart - me.slideHeight;
	    var endFrame = 0 - ((me.slideTotal-1) * me.slideHeight);
	     
	    var addIncrement;
	    if ((loopI + me.slideIncrement) > me.slideHeight){

	         addIncrement = me.slideHeight -loopI;
	    } else {
	        addIncrement = me.slideIncrement;
	    }

	    loopI += me.slideIncrement;
	    if(slideEnd <= endFrame){
		     document.getElementById(me.nextButton).style.display = "none";
	    }
	    
	    document.getElementById(me.slideContainer).style.top = slideStart - addIncrement + 'px';
	    if(loopI>=me.slideHeight){
	        document.getElementById(me.nextButton).setAttribute('href',me.nextUrl);
		    clearInterval(goNext);
		    loopI = 0;
	    }
    }
    
    function prevSlideDetail(){
        document.getElementById(me.prevButton).removeAttribute("href");
	    var slideStart = parseFloat(document.getElementById(me.slideContainer).style.top);
	    slideEnd = slideStart + me.slideHeight;    
	        
	    var addIncrement;
	    if ((loopI + me.slideIncrement) > me.slideHeight){
	         addIncrement = me.slideHeight -loopI;
	    } else {
	        addIncrement = me.slideIncrement;
	    }
	    loopI += me.slideIncrement;
 
	    document.getElementById(me.slideContainer).style.top = slideStart + addIncrement + 'px';
	    if(loopI>=me.slideHeight){
	        document.getElementById(me.prevButton).setAttribute('href', me.prevUrl);
		    clearInterval(goBack);
		    loopI = 0;
		    if(slideStart == -addIncrement){
		       document.getElementById(me.prevButton).style.display = "none";
		        document.getElementById(me.nextButton).style.display = "block";
		    } else {
                document.getElementById(me.nextButton).style.display = "block";
		    }
	    }
    }
}


//POSITIONING FOR TOOLTIP
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

function findPosY(obj)
  {
    var curtop = 0; 
    if(obj.offsetParent)
        while(1)
        {
         
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function tooltip(divid){	
	var xzero = findPosX(document.getElementById('gridwrapper'));
	var yzero = findPosY(document.getElementById('gridwrapper'));
	var e = document.getElementById(divid);
	var qv = document.getElementById('tooltip');
	var x = findPosX(e) - xzero;
	var y = findPosY(e) - yzero;
	//alert('test');
	qv.style.left = x-6 + 'px';
    qv.style.top = y+15 + 'px';
    $('tooltip').style.display = "block";
    $('tooltip').onmouseover = function() {
        $('tooltip').style.display = "block";
        
    }
	$(divid).onmouseout = function() {
        $('tooltip').style.display = "none";
    }
    $('tooltip').onmouseout = function() {
        $('tooltip').style.display = "none";
    }
}

function InitializeToolTips(){

    var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++){
		if (x[i].id.indexOf('icon')>-1){
            var pageid = x[i].id.replace('icon','');
            var iconid = x[i].id;
            var tooltipid = 'tooltip' + pageid;
            //var eventicon = 'eventtypeimg' + pageid;
            
		    $(iconid).onmouseover = function(){
		        this.style.position = "relative";
		        var toolid = 'tooltip' +  this.id.replace('icon','');
		        $(toolid).style.display = "block";
		        var eventid = 'eventtypeimg' +  this.id.replace('icon','');
		        var roll = $(eventid).src.replace("/large/","/large/on/");
		        if (roll.indexOf('/on/on') == -1){
		            $(eventid).src = roll;
		        }
		    }
		    
		    $(tooltipid).onmouseover = function(){
		
		        $(this.id).style.display = "none";
		    
		    } 

		    $(iconid).onmouseout = function(){
		        var tooltipid = 'tooltip' +  this.id.replace('icon','');
		        $(tooltipid).style.display = "none";
		        //this.style.position = "static";
		        
		        var eventid = 'eventtypeimg' +  this.id.replace('icon','');
		        var roll = $(eventid).src.replace("/large/on/","/large/");
		        
		            $(eventid).src = roll;
		        
		        
		        
		    }
		    
//		    $('tooltip' + pageid).onmouseout = function(){
//		       $(this.id).style.display = "none";
//		    }
		}
    }
}

function hoverdates(){
    var x=document.getElementsByTagName("td");
	for (var i=0;i<x.length;i++){
		if (x[i].className.indexOf('vDay')>-1){
		    x[i].style.cursor = 'pointer';
		    x[i].onmouseover = function(){
		        this.style.backgroundColor = '#fff';
		    }
		    x[i].onmouseout = function(){
		        this.style.backgroundColor = '#f0ede3';
		    }
//		    x[i].onclick = function(){
//		        document.location.href = '/list.aspx?day=';
//		    }
		}
    }
}

function clearfield(id){
    $(id).value = '';
}

function searchitem(id,title){
	var x=document.getElementsByTagName("div");
	for (var i=0;i<x.length;i++){
		if (x[i].id.indexOf(id)>-1){
		    x[i].onmouseover = function(){
		        this.style.backgroundColor = '#f6f4ef';
		        var handle = this.id.replace(id,'');
		        var searchtitle = title + handle;
		        $(searchtitle).style.color = '#e9376B';
		    }
		    x[i].onmouseout = function(){
		        this.style.backgroundColor = '#fff';
		        var handle = this.id.replace(id,'');
		        var searchtitle = title + handle;
		        $(searchtitle).style.color = '#342e2e';
		    }
		}
	}
}

function joinhover(name,img){
    var x=document.getElementsByTagName("a");
	for (var i=0;i<x.length;i++){
	    if (x[i].id.indexOf(name)>-1){
		    x[i].onmouseover = function(){
		        var handle = this.id.replace(name,'');
	            var arrow = img + handle;
		        $(arrow).src = '/images/arrowon.gif';
		    }
            x[i].onmouseout = function(){
                var handle = this.id.replace(name,'');
	            var arrow = img + handle;
	            $(arrow).src = '/images/arrowoff.gif';
	        }
	    }
	}
}

imgout = new Image(9, 9);
imgin = new Image(9, 9);
imgout.src = "/images/buttons/arrow_right.gif";
imgin.src = "/images/buttons/arrow_down.gif";

function filter(imagename, objectsrc) {
    if (document.images) {
        document.images[imagename].src = eval(objectsrc + ".src");
    }
}

function shoh(id, returncolor) {
    if (document.getElementById('div' + id).style.display == "none") {
        filter(('voom' + id), 'imgin');
    } else {
        filter(('voom' + id), 'imgout');
    }
}

window.onload = masterloader;

function masterloader(){
    joinhover('joinlink','arrow');
    hoverdates();
	rolloverInit();
	spidermenus('menutrigger','menu');
	InitializeToolTips();
	searchitem('searchresult','searchtitle');
	//nav('drop');

}