var sendToAFriendCount = 1;
timeout = 'notSet';

$(document).ready(function() {
    populateElement('#keywords', 'Search 3am');
	
	$('.dropDown ul').hide();
		
		
	$('#ddOne').click(function () { 
    	ddOn('#ddOne');
    }).mouseleave(function () { 
    	ddOff('#ddOne'); 
    }).css({'cursor' : 'pointer', 'position' : 'absolute'});
	
	
	$('#ddOnedd').mouseleave(function () { 
    	ddOff('#ddOne'); 
    }).css({'position' : 'absolute'})
	.mouseenter(function () {
		ddOn('#ddOne');
	});
	
	
	
	$('#ddTwo').click(function () { 
    	ddOn('#ddTwo');
    }).mouseenter(function () { 
    	ddOff('#ddTwo'); 
    }).css({'cursor' : 'pointer', 'position' : 'absolute'});
	
	
	$('#ddTwodd').mouseleave(function () { 
    	ddOff('#ddTwo'); 
    }).css({'position' : 'absolute'})
	.mouseenter(function () {
		ddOn('#ddTwo');
	});
});


function populateElement(selector, defvalue) {
    if($.trim($(selector).val()) == "") {
        $(selector).val(defvalue);
    }
  
    $(selector).focus(function() {
        if($(selector).val() == defvalue) {
            $(selector).val("");
        }
    });
    
    $(selector).blur(function() {
        if($.trim($(selector).val()) == "") {
            $(selector).val(defvalue);
        }
    });
 }
 
 
 // Drop Down
 function ddOn(ddId) {
	if(timeout == 'set') {
		//alert('trying to re-set timout!');
		clearTimeout(thisTimeout);
		var theDD = ddId + 'dd';
 		$(theDD).slideDown();
	} else {
		var theDD = ddId + 'dd';
 		$(theDD).slideDown();
	}
	
 	
 }

 function ddOff(ddId) {
 	thisTimeout = setTimeout('closeDD("' + ddId + '")', 700);
	timeout = 'set';
 }
 
 function closeDD(ddId) {
 	theDD = ddId + 'dd';
 	$(theDD).slideUp();
 }
 
 
 // Rated tabs
 function tabed(shID) {
	try {
		$(tabLastID).removeClass('selected');
		$(tabLastID).parent().css({'z-index' : '8'});
		$(tabLastID + 'DD').hide();
	}catch(e){}
		
	$(shID).parent().css({'z-index' : '2'});
	$(shID).addClass('selected');
	$(shID + 'DD').show();
	tabLastID = shID;
}
 
 // Lightbox
 function popUp(popupHtml,whichPopup) {
		// Inserts the black background
		$('#pageWrap').after('<div class="nockBack"></div>');
		$('.nockBack').css('height',$(document).height()).css('opacity','0.7').css('z-index','5').css('width',$(window).width());
		
		if (whichPopup == 'friend') {
			sendToFriend(popupHtml);
		} else {
			share(popupHtml);
		}
	}

function sendToFriend(popupHtml) {
		// Inserts the HTML and positions in center of the screen
		$('.nockBack').after('<div id="popupWin"></div>');
		$('#popupWin').load(popupHtml);
		var leftPosition = $(window).width()/2-302;
		$('#popupWin').css('left', leftPosition + 'px').css('display', 'block');
	}

function share(popupHtml) {
		// Inserts the HTML and positions in center of the screen
		$('.nockBack').after('<div id="popupWin"></div>');
		$('#popupWin').load(popupHtml);
		var leftPosition = $(window).width()/2-200;
		$('#popupWin').css('left', leftPosition + 'px').css('display', 'block');
	}

function closePopup() {
		$('.nockBack').remove();
		$('#popupWin').remove();
	}

 
 function addEmail() {
 	sendToAFriendCount++;	
	if (sendToAFriendCount <= 5) {
		$('#emlLst').append('<input name="email' + sendToAFriendCount + '" type="text" value="" />');
	}
 }
 
 
 
 
 