// All Functions to be used on a page to page basis
var BASE_URL = '';
var popts = '';
var ccats = '';
var hpbtnarr = new Array('new-to-site','categories','locations','why-choose-us');
// Switch State allows the dynamic switching of the tabs and content
// tabsActive, tabsDown, show, hide
function dEI(obj){ return document.getElementById(obj);}
var lastCont = 'new-to-site-cont';

function switchState(mainObj){
			$('#'+lastCont).hide();
			lastCont = $('#'+mainObj+'-cont');			
	for(var k = 0; k < hpbtnarr.length;k++){
		if(hpbtnarr[k] == $('#'+mainObj).attr('id')){
			var opendiv = $('#'+mainObj+"-cont");
			opendiv.show();
			lastCont = opendiv.attr('id');
			if($('#'+mainObj).hasClass('tabsDown')) $('#'+mainObj).removeClass('tabsDown');
			$('#'+mainObj).addClass('tabsActive');
		} else {
			if($('#'+hpbtnarr[k]).hasClass('tabsActive')) $('#'+hpbtnarr[k]).removeClass('tabsActive');
			$('#'+hpbtnarr[k]).addClass('tabsDown');
		}
	}
}

/*function changeWin(div,newh){
	$('#'+lastDiv).animate({alpha:0},500);
	setTimeout("$('#midwindow').animate({height:'"+ newh +"px;'},200)");
//	lastDiv = div;
	var appWait = 300;
	if(div == "byform" || lastDiv == "byform") {appWait = 800;}
	setTimeout("Effect.Appear('"+div+"')",appWait);
	rlink = div + '-link';
	$(rlink).className = "tabsActive";
	lastLink = lastDiv + '-link';
	$(lastLink).className = "tabsDown";
	lastDiv = div;
}*/


/*function getxmlhttp(){
var xmlhttp = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  	xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
  	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}
*/

function getFreshContent(obj,page){
	$.ajax({ 
		url: page, 
		global: false,
		type: "GET",
		dataType: "html",
		success: function(mess){
			$('#'+obj).innerHTML = mess;
		}
	});	
}
//check for user/pass and login
function checkForUser(formname){
	var f = document.forms[formname];
	var un = f.username.value;
	var pass = f.password.value;
	
	$.ajax({
	      url: "/controller/logincheck.php",
	      global: false,
	      type: "POST",
	      data: ({username : un, password: pass}),
	      dataType: "html",
	      success: function(msg){
	         if(msg == 'passed'){
				$('#loginerr').hide();
				window.location = window.location;
			} else {
				$('#loginerr').show();
				$('#loginerr').html('<span class="error">login failed</span>');
			}
	      }
	});
}
// get video and return into website
function govid(obj, catid, catname){
	//catname = catname.replace(' ','-');
	$.ajax({
	      url: BASE_URL+"/controller/snatchvid.php?catid="+catid,
	      type: "GET",
	      dataType: "html",
	      success: function(msg){
	        var fullvideo = '<div style="text-align:center;"><embed height="240" width="320" scale="noscale" flashvars="video='+msg+'" quality="high" name="pav_hp_vid" src="swf/pav_hp_player.swf" type="application/x-shockwave-flash" id="pav_hp_vid"/></div>';
			fullvideo = fullvideo + '<div class="coolbtn float-left block margtopten linkdark"><a href="/aerialvideo/categories/view/'+catname+'&cat=default&isnum=no&r=20">View This Collection</a></div>';
			$('#'+obj).html(fullvideo);
			$('#'+obj).show();
	      }
	});
}
// toggle an object (block/none)
function toggleThis(obj){
	if($('#'+obj+':visible')){
		$('#'+obj).hide();
	} else {
		$('#'+obj).show();
	}
}
// ajax call to videopage, get xml data back, parse, show on page
// main video window that pops up over search results
function getVid(obj,prod_id){
	$.ajax({
	  url: '/controller/returnvideo.php?product_id='+prod_id,
	  success: function(data) {
		$('#'+obj).html(data);
		$('#popwin').show();
		$('#dim').show();
	  }
	});
}
// main notice mechanism, flash = notice, shows at top of screen
function flash(obj,text){
	$('#'+obj).html(text);
	$('#'+obj).show();
	$('#'+obj).animate({opacity:1},1000, function(){
		setTimeout(function(){$('#'+obj).fadeOut();},3000);
	});
}

// Function -- lbAdd - async add to lightbox from search or category page
// returns success - "true" or err - "err"
// flash will display a message for added, or err
function lbAdd(pid,pagenote){
	$.ajax({
	  url: BASE_URL+'/controller/lboxactions.php?req=add&pid='+pid,
	  success: function(data) {
		if(data == "true"){
			flash('pagenote',"<p class=\"success\">Video Clip added to your Lightbox. <a href=\"/lightbox/show/\" class=\"medgray\">View Your Lightbox</a></p>");
			getLBCount();
		} else {
			flash('pagenote',"<p class=\"errortxt\">Video Clip could not be added to your Lightbox</p>");
		}
	  }
	});
}
// get number of lightbox items
function getLBCount(){
	$.ajax({
	  url: BASE_URL+'/controller/lboxactions.php?req=num',
	  success: function(data) {
		$('#lbcount').html('('+data+')');
	  }
	});
}
//delete a video from your Lightbox
function delVid(pid){
	$.ajax({
	  url: BASE_URL+'/controller/lboxactions.php?req=remove&pid='+pid,
	  success: function(data) {
		if(data == "true"){
			window.location = window.location;
		} else {
			flash('pagenote',"<p class='errortxt'>Item could not be removed from your Lightbox</p>");
		}
	  }
	});
}

function download(pid){
	//getvideo.php?vid='.$row['product_id'].'
	var page = '/getvideo.php?vid='+pid;
	/*var params = 'vid='+pid;
	var page = BASE_URL+'/controller/forcedownload.php';
	xmlhttp.open("POST",page, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) if(xmlhttp.responseText == 'fail') flash('pagenote',"<p class='errortxt'>Video couldn't be downloaded. We're sorry about the inconvenience</p>");
	}
	xmlhttp.send(params);
	*/
	window.location.href = page;
}

function show(obj){
	$('#'+obj).show();
}

/*function makeDim(){
	if(!dEI('dim')){
		$bodytags = document.getElementsByTagName('body');
		$body = $bodytags[0];
		$ndim = document.createElement('div');
		$ndim.id = "dim";
		$ndim.name = "dim";
		$ndim.className = "overlay";
		$ndim.style.display = "none";
		$body.appendChild($ndim);
	}
}*/

function makePop(){
	if(!dEI('popwin')){
		$bodytags = document.getElementsByTagName('body');
		$body = $bodytags[0];
		$pop = document.createElement('div');
		$pop.id = "popwin";
		$pop.name = "popwin";
		$pop.className = "videowin";
		$pop.style.display = "none";
		$body.appendChild($pop);
	}
}

function makeToolTip(){
	if(!dEI('tooltip')){
		$bodytags = document.getElementsByTagName('body');
		$body = $bodytags[0];
		$tooltip = document.createElement('div');
		$tooltip.id = "tooltip";
		$tooltip.name = "tooltip";
		$tooltip.className = "infotip";
		$tooltip.style.display = "none";
		$body.appendChild($tooltip);
	}
}

function kill(obj){
	if($('#'+obj).length > 0){
		$('#'+obj).html('');
		$('#'+obj).hide();
		if($('#'+obj).hasClass("show")){
			$('#'+obj).removeClass('show').addClass("hide");
		}
	}
}

function getToolTip(obj,ref,text,e){
	theXOffset = e.pageX;
	theYOffset = e.pageY;
	var winX = $(document).width();
	var winY = $(document).height();
	$('#'+obj).show();
	$('#'+obj).css("top", (theYOffset + 20)+"px");
	if((theXOffset - 150) <= 0){
		$('#'+obj).css("left",(theXOffset)+"px");
	} else if(theXOffset + 150 > winX){
		$('#'+obj).css("left",(theXOffset - 300)+"px");
	} else {
		$('#'+obj).css("left",(theXOffset - (150))+"px");
	}
	$('#'+obj).html(text);
}
//add or modify a category
function addmodcat(target,type,casetype,childOf){
	var id = dEI(target).value;
	var serverPage = '../../controller/doCat.php?id='+id+'&type='+type+'&case='+casetype+'&child='+childOf;
	$.ajax({
		url: serverPage,
		success: function(data) {
			if(data == "true"){
				window.location = window.location;
			} else {
				alert('Failed to make parent category. Already Exists');
	  		}
		}
	});
}
// target (subcat), childOf (type), 'addchild' (casetype), parent (parent category current)
function addaschildof(target,type,casetype,pcats){
	var pid = dEI(pcats).value;
	addmodcat(target,type,casetype,pid);
}

//add a category
function doaddcat(name,type,status){
	if(dEI(name).value == ''){
		alert('You need to add a name to create a new Category');
	} else {
		var name = dEI(name).value;
		var type = dEI(type).value;
		var status = dEI(status).checked;
		var serverPage = '../../controller/doCat.php?case=addcat&type='+type+'&name='+name+'&status='+status;
		$.ajax({
		  url: serverPage,
		  success: function(data) {
			if(data == "true"){
				alert('category created.');
				window.location = window.location;
			} else {
				alert('Category already exists');
		  	}
			}
		});
	}
}

function switchMod(target,type,inputdiv,public){
	var id = dEI(target).value;
	var status = dEI(public).checked;
	var serverPage = '../../controller/doCat.php?case=getcat&type='+type+'&id='+id;
	$.ajax({
		url: serverPage,
		success: function(data) {
			var code = data.split(':');
			$('#'+inputdiv).val(code[0]);
			if(code[1] == '0'){
				$('#'+public).attr('checked') = 'true';
			} else {
				$('#'+public).removeAttr('checked');
			}
		}
	});
}

function updateCat(target,textel,status,type){
	if($(textel).value == ''){
		alert("You need to actually add a Cateory name to rename the Category to that name");
	} else {
		var id = $(target).value;
		var name = $(textel).value;
		var status = $(status).checked;
		var serverPage = '../../controller/doCat.php?case=modcat&type='+type+'&id='+id+'&name='+name+'&status='+status;
		$.ajax({
			url: serverPage,
			success: function(data) {
				if(data == "true"){
					alert('Category Modified');
					window.location = window.location;
				} else {
					alert("error updating category");
				}
			}
		});
	}
}
// Share Lightbox
function shareLB(lbid,uid){
	//bring in form
	// popup in popwin
	var form = "<div class=\"lrgform\"><div class='float-right margleftten margbtmten closelarge'><a class='nodeclink' onclick=\"kill(\'popwin\');\" href='javascript://'><img height='20' width='24' border='0' alt='close' src='../../../images/closepop.gif'/></a></div><h3 class='normtxt medblue mt mbf nintyper block'>Share your Lightbox</h3><form name='shareLB' method='' action='' id='shareLB'><span class='block'><textarea id='sharewith' name='sharewith' class='sInputTA'>Share your Lightbox with up to 10 people. Use commas to separate email addresses.</textarea></span><span class=\"block\"><label for='message' class='white mbf block'>Add a Note:</label><textarea id='message' name='message' class='sInputTA'>Add a personal note.</textarea></span><span class='block'><input type='button' name='share' id='share' onclick=\"sendLBShare('"+lbid+"','"+uid+"');\" value='Share Lightbox'/></span></form></div>";
	$('#popwin').html(form);
	$('#popwin').show();
}

function sendLBShare(lbid,uid){
	//get email addresses, or email address
	// get message, strip baddies
	//alert($('#sharewith').val() + ' '+$('#message').val() + ' '+lbid+' '+uid);
	var emails = $('#sharewith').val();
	var sendmess = $('#message').val();
	var errors = '';
	var err = false;
	//
	if(emails == 'Share your Lightbox with up to 10 people. Use commas to separate email addresses.'){
		errors += "<span class='mr'>You need to add an email address to Share this Lightbox</span>";
		err = true;
	}
	if(sendmess == 'Add a personal note.'){
		sendmess = "default";
	}
	if(!err){
	$.ajax({
		url: BASE_URL+"/controller/sendShareMail.php",
	    type: "POST",
	    data: "e="+emails+"&mess="+sendmess+"&lbid="+lbid+"&uid="+uid,
	    dataType: "html",
		success: function(data) {
			if(data == "true"){
				kill('popwin');
				//flash emails sent out
				flash('pagenote',"<p class=\"success\">You just Shared your Lightbox.</p>");
			} else {
				//if not true, just an error message, to flash
				alert(data);
			}
		}
	});
	} else {
		flash('pagenote',"<p class='errortxt'><b>Opps. "+errors+"</b></p>");
	}
}

function moveToCats(div){
	/*Effect.ScrollTo(div);*/
}

function showThumbs(div,elem){
	if(elem.className == 'plus doright'){
		elem.className = 'minus doright';
	} else {
		elem.className = 'plus doright';
	}
	showBox(div);
}

function showBox(q){
		if(dEI(q).style.display == "none"){
			$('#'+q).slideDown();
		} else{
			$('#'+q).slideUp();
		}
}

// Contact Us Page
var lastDiv = "byform";
var div;
var newh;
var appWait;
// contact windows (3)
function changeWin(pdiv,pnewh){
	div = pdiv;
	newh = pnewh;
	$('#'+lastDiv).fadeOut(1000, function(){morphCont();});
	if(div == "byform" || lastDiv == "byform") appWait = 1000; else appWait = 300;
	rlink = div + '-link';
	$('#'+rlink).removeClass('tabsDown').addClass("tabsActive");
	lastLink = $('#'+lastDiv+'-link');
	lastLink.removeClass('tabsActive').addClass("tabsDown");
	lastDiv = div;
}

function morphCont(){
	//alert('appear');
	//var h = newh+'px';
	//new Effect.Morph('midwindow', {style: 'height:'+h+';',duration:0.8});
	//setTimeout(insertCont,appWait);
	//new Effect.Morph('midwindow', { style: 'height:"'+ newh +'"px;', duration:1, complete:insertCont});
}

var lastBtn = "forgotpw";

function fadeInOut(div){
	$('#'+lastBtn+'_btn').removeClass('tabsActive').addClass('tabsDown');
	$('#'+div+'_btn').removeClass('tabsDown').addClass('tabsActive');
	$('#'+lastBtn).fadeOut();
	setTimeout(function(){$('#'+lastBtn).fadeIn();},500);
	lastBtn = div;
}

function insertCont(){
	$('#'+div).fadeIn();
}

function makeShareForm(){	
}

function doFire(e){
	if(e.keyCode == '13') {
		if($('#username').length > 0){
			if($('#username').val() != 'username' && $('#password').val() != 'password'){
				checkForUser('pav_member_login');
			}
		}
		/*if($('#q').focus()){
			//goSearch();
		}*/
	}
}
// fire search function
function goSearch(){
	if($('#q').val() != 'search for clips'){
		doSearch('/stockfootage/search/view/','filters','q','cat','isnum','r','0');
	}
}
// fire filter actions
function doFilter(uri,filtertype,searchword,category,isnumeric,results,start){
	var uri = uri;
	if($('#'+filtertype).val() != '0') uri += '&filters='+$('#'+filtertype).val();
	if(searchword != '') uri += '&q='+searchword;
	if(category != '') uri += '&cat='+category;
	if(isnumeric != '') uri += '&isnum='+isnumeric;
	if(results != '') uri += '&r='+results;
	if(start != '') uri += '&start='+start;
	window.location.href = uri;
}
// big search
function doSearch(uriroot,filters,q,cat,isnum,results,start){
	if($('#'+q).val() != 'search for clips'){
		var search = BASE_URL+''+uriroot;
		if($('#'+q).val() != '' || $('#'+q).val() != 'search for clips') search += $('#'+q).val();
		if($('#'+filters) && $('#'+filters).val() != 'def') search += '&fitlers='+$('#'+filters).val();
		if($('#'+cat).length > 0 && $('#'+cat).val() != '') search += '&cat='+$('#'+cat).val();
		if($('#'+isnum).length > 0 && $('#'+isnum).val() != '') search += '&isnum='+$('#'+isnum).val();
		if($('#'+results).val() != '') search += '&r='+$('#'+results).val();
		window.location.href = search;
	} else {
		flash('pagenote',"<p class='errortxt'><b>You need to add your own Search term or Phrase to Search our Stock Footage Collections.</b></p>");
	}
}

function sUpdate(type,value){
	if(type == 'cat'){
		$('#isnum').val() = 'no';
		$('#q').val() = 'all';
	} else if(type == 'isnum'){
		$('#cat').val() = 'default';
		if(value == 'yes') $('#q').val() = 'ex: 131-1001'; else $('#q').val() = 'all';
	}
}

function deleteLB(lid){
	var del = confirm('Are You Sure you Want to Delete this Lightbox?');
	if(del){
		var serverPage = '../../controller/deleteLB.php?lid='+lid;
		$.ajax({
		  url: serverPage,
		  success: function(data) {
			if(data == "true"){
				window.location = window.location;
			} else {
				alert("error deleting Lightbox");
			}
			}
		});
	}
}

if($('#locations-cont').length > 0){
var alreadyset=0;
var longval = "x";
var latval = "y";
var first = 0;
var i = 0;
var gmarkers = [];
var htmls = [];
var IMAGES = ["pin2"];
var ICONS = [];
var names = [];
var cat_id = [];
var cat_name = [];
var select_html;
var map;
//
var geo = new GClientGeocoder(new GGeocodeCache()); 
var reasons=[];
reasons[G_GEO_SUCCESS]            = "Success";
reasons[G_GEO_MISSING_ADDRESS]    = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS]    = "Unknown Address:  No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address:  The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY]            = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES]   = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR]       = "Server error: The geocoding request could not be successfully processed.";
//
// builds out the map
function buildMap(){
	map = new GMap2(document.getElementById("mapper"));
	map.setMapType(G_NORMAL_MAP);
	map.enableDoubleClickZoom();
	map.setCenter(new GLatLng(35.62158189955968,-99.5205078125),4);
	select_html = '<select onChange="handleSelected(this)"><option selected> - Select a location - </option>';
	map.setUIToDefault();
	// trigger markers to load
	loadXMLMarkers();
}
// used to target long / lat points
function addClickList(){
	GEvent.addListener(map, 'click', function(overlay, point) {
		if (overlay && alreadyset) {
			map.removeOverlay(overlay);
			alreadyset = 0;
		} else if (point && !alreadyset) {
			map.addOverlay(new GMarker(point));
			alreadyset = 1;
			longval = point.x;
			latval =  point.y;
			//document.getElementById('latitude').value = latval;
			//document.getElementById('longitude').value = longval;
		} else if (point && alreadyset) {
			alert("You can only select one location.Click on current location to remove point.");
		}
	});
}

function showToolTip(val,id){
	//
}
function closeTool(){
	//
}
// used to create Map Markers
function createMarker(point,label,html,depth,catid) {
	var marker = new GMarker(point, { icon: getIcon() })
	GEvent.addListener(marker, "click", function(depth) {
		marker.openInfoWindowHtml(html);
		for(var k=0; k < gmarkers.length;k++){
			if(gmarkers[k] == this){
				var cat = cat_id[k];
				var name = cat_name[k];
				govid('govidhp', cat, name);
			}
		}
    });
	GEvent.addDomListener(marker, "mouseover", function(){
		showToolTip(depth,catid);
	});
	GEvent.addDomListener(marker, "mouseout", function(){
		closeTool();
	});
		names[i] = label;
    gmarkers[i] = marker;
    htmls[i] = html;
    cat_id[i] = catid;
		cat_name[i] = label;
    select_html += '<option> ' + label + '</option>';
    i++;
	return marker;
}
// used to add a random marker to the map, if we feel like switching up a featured icon, etc
function getIcon() {
	var i = Math.floor(IMAGES.length*Math.random());
	if (!ICONS[i]) {
		var icon = new GIcon();
	  	icon.image = "images/" + IMAGES[i] + ".png";
	  	icon.iconAnchor = new GPoint(0, 0);
	  	icon.infoWindowAnchor = new GPoint(0, 0);
	  	icon.iconSize = new GSize(7, 18);
	  	ICONS[i] = icon;
	 }
	 return ICONS[i];
}
// function to handle action of selecting a location - triggers a computer based mouse click   
function handleSelected(opt) {
	var i = opt.selectedIndex - 1;
	if (i > -1) {
		//GEvent.trigger(gmarkers[i],"click");
		var tmp = gmarkers[i];
		GEvent.trigger(tmp,"click");
		// inject video into right column
		// trigger event seems to be busted
	} else {
		map.closeInfoWindow();
	}
}
// used to place a marker at a search location - based off of geo search
function showAddress(address) {
	geo.getLatLng(
	address,
	function (point){ 
		if (!point) {
			alert(address + " not found");
		} else {
			var marker = new GMarker(point);
			map.addOverlay(marker);
			map.setCenter(point,14);
			longval = point.x;
			latval =  point.y;
			//document.getElementById('latitude').value = latval;
			//document.getElementById('longitude').value = longval;
		} 
	}
);
}
// used to load all of the dynamic markers from the PHP based XML file
function loadXMLMarkers(){
	GDownloadUrl("controller/hp_map_markers.php", function(data, responseCode) {
	var xmlDoc = GXml.parse(data);
    var markers = xmlDoc.documentElement.getElementsByTagName("marker");
	for (var i = 0; i < markers.length; i++) {
		// obtain the attribues of each marker
		var lat = parseFloat(markers[i].getAttribute("lat"));
		var lng = parseFloat(markers[i].getAttribute("lng"));
		var point = new GLatLng(lat,lng);
		var html = markers[i].getAttribute("html");
		var catid = markers[i].getAttribute("catid");
		var label = markers[i].getAttribute("label");
        // create the marker
        var marker = createMarker(point,label,html,i,catid);
        map.addOverlay(marker);
    }
    // ===== final part of the select box =====
    select_html += '</select>';
   document.getElementById('location_txt').innerHTML = select_html;
	});
}
// refreshes the map upon the users first time opening up the maps 
// tab - fixes redraw issues in Firefox for Mac OSX

function gofresh(){
	if(first <= 0){
		buildMap();
		first = 1;
	} 
}
}

var aCont = new Array('byphone','byemail','byform');

function toggleDiv(div,elem){
	for(var g=0;g < aCont.length;g++){
		if(div != aCont[g]){
			$('#'+aCont[g]).hide();
			$('#'+aCont[g]+'-link').removeClass('tabsActive').addClass('tabsDown');
		} else if(div == aCont[g]){	
			$('#'+div).show();
			$('#'+div+'-link').removeClass('tabsDown').addClass('tabsActive');
		}
	}
}

$(document).ready(function() {
	$('#loginsubbtn').live("mouseover",function(){ if($('#loginsubbtn').hasClass('loginBtn')) $('#loginsubbtn').removeClass('loginBtn').addClass('loginBtnOver');});
	$('#loginsubbtn').live("mouseout",function(){ if($('#loginsubbtn').hasClass('loginBtnOver')) $('#loginsubbtn').removeClass('loginBtnOver').addClass('loginBtn');});
	$('#searchbtn').live("mouseover",function(){ if($('#searchbtn').hasClass('searchBtn')) $('#searchbtn').removeClass('searchBtn').addClass('searchBtnOver');});
	$('#searchbtn').live("mouseout",function(){ if($('#searchbtn').hasClass('searchBtnOver')) $('#searchbtn').removeClass('searchBtnOver').addClass('searchBtn');});	
	$('#username').focus(function(){ if($('#username').val() == 'username') $('#username').val('');});
	$('#username').blur(function(){ if($('#username').val() == '') $('#username').val('username');});
	$('#password').focus(function(){ if($('#password').val() == 'password') $('#password').val('');});
	$('#password').blur(function(){ if($('#password').val() == '') $('#password').val('password');});
	$('#q').focus(function(){
		$('#extraoptions').fadeIn();
		if($('#q').val() == 'search for clips') $('#q').val('');
	});
	$('#q').blur(function(){ if($('#q').val() == '') $('#q').val('search for clips'); });
	$('#logo').live("click",function(){ window.location.href = "/"; });
	$('#new-to-site').live("mouseover",function(){ if($('#new-to-site').hasClass('tabsDown')) $('#new-to-site').removeClass('tabsDown').addClass('tabsOver'); });
	$('#new-to-site').live("mouseout", function(){ if($('#new-to-site').hasClass('tabsOver')) $('#new-to-site').removeClass('tabsOver').addClass('tabsDown'); });
	$('#new-to-site').live("click",function(){ switchState('new-to-site'); });
	$('#categories').live("mouseover", function(){ if($('#categories').hasClass('tabsDown')) $('#categories').removeClass('tabsDown').addClass('tabsOver'); });
	$('#categories').live("mouseout", function(){ if($('#categories').hasClass('tabsOver')) $('#categories').removeClass('tabsOver').addClass('tabsDown'); });
	$('#categories').live("click", function(){ switchState('categories'); });
	$('#locations').live("mouseover", function(){ if($('#locations').hasClass('tabsDown')) $('#locations').removeClass('tabsDown').addClass('tabsOver'); });
	$('#locations').live("mouseout", function(){ if($('#locations').hasClass('tabsOver')) $('#locations').removeClass('tabsOver').addClass('tabsDown');});
	$('#locations').live("click",function(){
		switchState('locations');
		gofresh();
	});
	$('#why-choose-us').live("mouseover", function(){ if($('#why-choose-us').hasClass('tabsDown')) $('#why-choose-us').removeClass('tabsDown').addClass('tabsOver');});
	$('#why-choose-us').live("mouseout", function(){ if($('#why-choose-us').hasClass('tabsOver')) $('#why-choose-us').removeClass('tabsOver').addClass('tabsDown');});
	$('#why-choose-us').live("click", function(){ switchState('why-choose-us');});
	$('#subscribe-to-feed').live("click", function(){ window.location.href = $('#subscribe-to-feed').attr('rel');});
	// share lb
	$('#sharewith').live("focus", function(){
		if($(this).val() == 'Share your Lightbox with up to 10 people. Use commas to separate email addresses.') $(this).val('');
	});
	$('#sharewith').live("blur", function(){
		if($(this).val() == '') $(this).val('Share your Lightbox with up to 10 people. Use commas to separate email addresses.');
	});
	$('#message').live("focus",function(){
		if($(this).val() == 'Add a personal note.') $(this).val('');
	});
	$('#message').live("blur",function(){
		if($(this).val() == '') $(this).val('Add a personal note.');
	});
	$('.download_clip').live("mouseover",function(event){
		getToolTip('tooltip',$(this),'Download a Sample of this Clip',event);
	});
	$('.download_clip').live("mousemove",function(event){
		getToolTip('tooltip',$(this),'Download a Sample of this Clip',event);
	});
	$('.download_clip').live("mouseout",function(event){
		kill('tooltip');
	});
	$('.ajaxadd').live("mouseover",function(event){
		getToolTip('tooltip',$(this),'Add this video to your lightbox',event);
	});
	$('.ajaxadd').live("mousemove", function(event){
		getToolTip('tooltip',$(this),'Add this video to your lightbox',event);
	});
	$('.ajaxadd').live("mouseout",function(){
		kill('tooltip');
	});
	$('#login_save_lb').live("click",function(){
		$('#pagenote').fadeOut('fast',function(){$('#username').focus();});
	});
	$('#save-lightbox-items-now').live("click",function(){
		$('#pagenote').html('<p>You need to Login to Save your Lightbox. <a href="javascript://" id="login_save_lb" class="medgray">Click Here to Login</a></p>');
	});
	$('#back_a_page').click(function(){
		history.back(1);
	});
	makePop();
	makeToolTip();
		//makeDim();	
	
});

