$(document).ready(function() {
	
	// redirect corporate link to a new window
	$('#corpLink').attr("target", "_blank");
	
	$('.flexslider').flexslider({
        controlNav: false,
        directionNav: false,
        slideshowSpeed: 7000,
        animationDuration: 600,
        animation: 'show'
	});
	
	// creating the filter by dropdown
	$('#locationFilter').change(function(){
		// check if it has &loc=#, if it does then replace it. Since this is added right
		// before submit, it will always be last.
		var $url = location.href;
		$url = $url.slice( 0, $url.indexOf('&loc') );
		
		// add new &loc.
		$url = $url + '&loc=' + $(this).val();
		window.location.href = $url;
	});
	
	
	// add lightboxes to specific images only
	$('div#product-photo a').addClass('lightbox');
	
	// lightbox for product images
	$(".lightbox").lightbox({
		fitToScreen:'true'
	});	
	
	 //Form text effects
	 $('#inputName').defaultvalues({focusaction:"clear"});
	 $('#inputEmail').defaultvalues({focusaction:"clear"});
	 $('.content-center form').defaultvalues({focusaction:"clear"});
	 
		/* employment application */
		var $allpanes = $(".tab-pane");
		$allpanes.hide();
		
		if ($('.form-error').length > 0)
		{
			$(".tab-pane:last").show();
		}
		else
		{
			$(".tab-pane:first").show();
		}
		
		$('.appnav a').click(function() {
			var $tab = $($(this).attr('href'));
			$allpanes.hide();
			$tab.show();
			return false;
		});
	
	
		// adding checkout to main content forms
		$('div.signup form').addClass('checkout');
		$('div.content-center form').addClass('checkout');
		
		
	/* ======= ALL SECTIONS ======== */


	
	/* open links in a new window */
	$ablank = $('a.blank, a.blank2');
	$ablank.click(function(){ window.open(this.href); return false; });
	$ablank.each(function() { if ($(this).attr('title') == '') { $(this).attr("title","Launches in a new window"); } } );
});

// the left column being at minimum the same size as the right. This will fix that
// by determining the size of the columns after the page has loaded all of the images
// and then it'll set the minimum height of #left to the height of right.
window.onload = function() {
	$('#left').css('min-height', $('#right').height());
}

$(window).ready(function() {
	
	if ($('#newsletter #error').length > 0)
	{
		$('html, body').animate({scrollTop: $("#footer").offset().top}, 500);
	}
	
	// whenever a left and right column exist, the site looks ugly without

});
// JavaScript Document
// begin top Navigation Script
//activateMenu = function(nav) {
function shipsame(form){
//alert ('included');

if(form.cntnt01sameasbilling.checked){

     form.cntnt01bill_first.value = form.cntnt01ship_first.value;
     form.cntnt01bill_last.value = form.cntnt01ship_last.value;
     form.cntnt01bill_addr.value = form.cntnt01ship_addr.value;
     form.cntnt01bill_addr2.value = form.cntnt01ship_addr2.value;     
     form.cntnt01bill_city.value = form.cntnt01ship_city.value;
     form.cntnt01bill_zip.value = form.cntnt01ship_zip.value;
     form.cntnt01bill_phone.value = form.cntnt01ship_phone.value;     
     form.cntnt01bill_cell.value = form.cntnt01ship_cell.value;
     
     if(form.cntnt01bill_state.type == "Select"){
          var bStateIdx = form.cntnt01ship_state.selectedIndex;
          form.cntnt01bill_state.options[bStateIdx].selected = true;
     }
     else{
          form.cntnt01bill_state.value = form.cntnt01ship_state.value;
     }
}
else{
     form.cntnt01bill_first.value = "";
     form.cntnt01bill_last.value = "";
     form.cntnt01bill_addr.value = "";
     form.cntnt01bill_addr2.value = "";     
     form.cntnt01bill_city.value = "";
     if(form.cntnt01bill_phone.type == "Select"){
          form.cntnt01bill_state.options[0].selected = true;
     }
     else{
          form.cntnt01bill_state.value = "";
     }
     form.cntnt01bill_city.value = "";
     form.cntnt01bill_zip.value = "";
     form.cntnt01bill_phone.value = "";
     form.cntnt01bill_cell.value = "";
}
}
/* currentStyle restricts the Javascript to IE only 
	if (document.all &&
 document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);*/
        
        /* Get all the list items within the menu 

        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {*/
        
           /* If the LI has another menu level 
            if(lis[i].lastChild.tagName=="UL"){*/
            
                /* assign the function to the LI 
             	lis[i].onmouseover=function() {	*/
                
                   /* display the inner menu 
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {   
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}
window.onload= function(){*/
    /* pass the function the id of the top level UL */

    /* remove one, when only using one menu 
    activateMenu('nav'); 
    activateMenu('vertnav'); 
}*/
function window_return()
{
alert ('here');
alert ('href='+this.href);
	//window.close();
	return this.href;
}
function terminate()
{
  var o = new Object();
  o.forename = document.getElementById("txtForename").value;
  o.surname = document.getElementById("txtSurname").value;
  window.returnValue = o; 
}
function popup(location_href,bank) {
//alert ('location_href='+location_href);
  F = window.open("index.php?page=leaving-site&loc="+location_href,"popup","width=400,height=300");
  //var oReturnValue = showModalDialog("index.php?page=notice");
 // alert("F="+F.href.link);
  //alert(F.forename + "\n" + F.surname);
  return false;
}
function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;


   sOptions = 'directories=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}
/*sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("li");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
sel = document.getElementsByTagName("select");
for (var i=0; i<sel.length; i++) {
sel[i].style.visibility = 'hidden';
}
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
sel = document.getElementsByTagName("select");
for (var i=0; i<sel.length; i++) {
sel[i].style.visibility = 'visible';
}
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

*/
/* Highlight input text elements */


function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}


function window_return()
{
alert ('here');
alert ('href='+this.href);
	//window.close();
	return this.href;
}
function terminate()
{
  var o = new Object();
  o.forename = document.getElementById("txtForename").value;
  o.surname = document.getElementById("txtSurname").value;
  window.returnValue = o; 
}
function popup(location_href,bank) {
//alert ('location_href='+location_href);
  F = window.open("index.php?page=leaving-site&loc="+location_href,"popup","width=400,height=300");
  //var oReturnValue = showModalDialog("index.php?page=notice");
 // alert("F="+F.href.link);
  //alert(F.forename + "\n" + F.surname);
  return false;
}
function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;


   sOptions = 'directories=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}


/* Highlight input text elements */


function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}

var currentState;
var playingFlag=false;
var currentPosition;
var currentVolume;
var currentItem;

function sendEvent(typ,prm) { thisMovie("videoplayer").sendEvent(typ,prm); };
function getUpdate2(typ,pr1,pr2,pid) {
     //sendEvent("stop");
	if(pid != "null") {
		if((typ == "state")&&(pr1 != undefined)) { 
			currentState = pr1;
                        //alert ('playingFlag='+playingFlag);
                        //filename = getUrlVars();
                     // alert ('currentState='+currentState);
                      
							if(currentState=="0") {
                                if (!playingFlag){
                                    playingFlag = true;
                                   //sendEvent('stop');
                                }
                                else{
                                   // itemnum = getPlayItem();
                                    //alert ('item='+itemnum);
                                   // sendEvent('playitem', 1);
                                }

			}
		}
	}
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
    if(navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};
        function getPlayItem()
        {
            filearray = getPlaylist();
            element = getUrlVars();
            for(var i=0; i<filearray.length; i++){
                if(filearray[i] == element){
                    return i;
                }
            }
            return -1;


        }
        function getPlaylist()
        {
            filearray = new Array(
                    'APLS_fall_harvest.flv',
                    'APLS_race.flv',
                    'APLS_spin_to_win.flv',
                    'BWF_grand_open_486.flv',
                    'BWF_halftime.flv',
                    'BWF_pick_your_room.flv',
                    'EZR_march_hoopla.flv',
                    'HRP_3_rooms.flv',
                    'HRP_get_it_486.flv',
                    'HRP_tis_season.flv',
                    'KELY_sweet_486.flv',
                    'R1_excitement.flv',
                    'R1_lucky_21_B.flv',
                    'R1_modern_marvels.flv',
                    'R1_summer52.flv',
                    'R1_tribute_to_you.flv',
                    'RCTY_25_year_B.flv',
                    'RCTY_take_me_home.flv',
                    'RCTY_tax_486.flv',
                    'STAT_8mo_SAC.flv',
                    'STAT_just_say_no.flv',
                    'UHR_gotta_go.flv',
                    'UHR_in_the_action.flv'
                    );
            return filearray;
        }
        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 hash[1];
        }
        function getPlaylistFile()
        {
            fh = fopen("playlist.xml", 0);
            if(fh!=-1) // Success
            {
                length = flength(fh);         
                str = fread(fh, length);   
                fclose(fh);                    
                alert(str);
                return str;
            }
            else
                return "error";
        }
	function getUpdate(typ,pr1,pr2,pid) {
	if (pid != "options"){
//	alert ("pid="+pid);
			if(typ == "time") { currentPosition = pr1; }
			else if(typ == "volume") { currentVolume = pr1; }
			else if(typ == "item") { 
				//alert ("pr1="+pr1);
				currentItem = pr1; 
				setTimeout("getItemData(currentItem)",100);		
				}
			var id = document.getElementById(typ);
			id.innerHTML = typ+ ": "+Math.round(pr1);
			pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
			if(pid != "null") {
				document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
			}
		}
	};
	
        function getItemData(idx) {
       // alert ('getItemData');
			var obj = thisMovie("videoplayer").itemData(idx);
			var nodes = "";
			for(var i in obj) { 
				if (i == "title")
					nodes = "Now Playing&nbsp;:&nbsp;"+obj[i];
					//nodes += "<li>"+i+": "+obj[i]+"</li>"; 
			
			}
			document.getElementById("nowplaying").innerHTML = nodes;
		};
      function createPlayer(player, playlist, divid, pname, width, height) {

       //createPlayer(player, playlist, divid, pname, width, height) {
       
       if (pname == "options")
       {
        	dwidth = width * 2;
        	linkfromdisplay = true;
        	overstretch = 'none';
        	repeat = "list";

        }
        else
        {
        	dwidth = width;
        	linkfromdisplay = false;
        	overstretch = false;
        	repeat = false
        	
        }
	whichPlayer = player;
          var so = new SWFObject(whichPlayer,pname,width,height,'7');
            so.addParam('allowfullscreen','false');
            so.addParam('allowscriptaccess','true');
            so.addVariable("file",playlist);
            so.addVariable('height',height);            
            so.addVariable('volume','100');
	        so.addVariable("rotatetime","1");              
            so.addVariable("enablejs","true");    
            so.addVariable('width',width);
            so.addVariable('autoscroll','false');
            so.addVariable('displaywidth',dwidth);
            so.addVariable('displayheight',height);
            so.addVariable('linkfromdisplay',linkfromdisplay);
            so.addVariable('repeat',repeat);
            
            so.addVariable('overstretch',overstretch);
            so.addVariable('thumbsinplaylist','false');
            so.addVariable("showicons","false");
            so.addVariable("javascriptid",pname);
            so.addVariable("autostart","true");
            so.addParam("menu","false");	
            so.write(divid);
        }
        

/* end */
      
      // get the url variables passed via $_GET
      $.extend({
    	  getUrlVars: function(){
    	    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;
    	  },
    	  getUrlVar: function(name){
    	    return $.getUrlVars()[name];
    	  }
    	});      
