//<![CDATA[
/*  
	File:walletpop-ca-functions.js    	
	Author: Lokesh Shetty
	Date: 21/01/2010
	Description : JS Methods to handle custom actions
	(c) Copyright 2008 AOL LLC	
	Dependencies : JQuery 1.3.2
	Attached on Document Ready
*/

if (!CaWalletpop) {var CaWalletpop = {};};
// Category highlight
CaWalletpop.selectedCategory = function(c) {
	if(!c) c = "main";
	$('#cat-'+c+' > a').addClass('catSelected');
}
// Handle first, last and even elements
CaWalletpop.documentAdjust = function() {
	//$("ul li:first-child").addClass("first");
	//$("ul li:odd").addClass("odd");
	//$("ul li:even").addClass("even");
	$("ul li:last-child").addClass("lastchild");
}
// Category drop down controls
CaWalletpop.rollOverMenu = function() {	
	$('#categoryNav ul[class=first] li a').each(function(){
		if($(this).attr("class").indexOf("noDropDown") == -1) {
			$(this).bind('mouseover', function() { 
				var cName = $.trim($(this).attr('class').replace(/ghSprite/i, '').replace(/catSelected/i, ''));
				$('#'+cName).attr('class', 'navOnRollover ' + cName);
			});
			$(this).bind('mouseout', function() {
				var cName = $.trim($(this).attr('class').replace(/ghSprite/i, '').replace(/catSelected/i, ''));
				$('#'+cName).attr('class', 'navRollover');
			});
		}
	});
	$('.navRollover').each(function() {
		$(this).bind('mouseover', function() {
			var cName = $(this).attr('id');
			$(this).attr('class', 'navOnRollover ' + cName); 
		});
		$(this).bind('mouseout', function() { 
			$(this).attr('class', 'navRollover'); 
		});		
	});
}
// Make homepage
CaWalletpop.makeHomePage = function(url) {
	$('#makeThisHome').bind('click', function(e) {
		// $(this).removeClass().addClass('setHomeClick');
		if (document.all) {
			this.style.behavior='url(#default#homepage)';
			this.setHomePage('http://'+url);
		}
		else {
			$('#setHome').fadeIn(1000);
		}
		e.preventDefault();
	});
	$('#setHome').bind('blur', function(){
		$('#setHome').fadeOut(1500);
	});
	$('#closeThis').bind('click', function(){
		// $('#setHome').removeClass().addClass('setHomeDefault');	
		$('#setHome').fadeOut(1000);
		// $('#setHome').removeAttr('style');
	});
}
// Send feed back link
CaWalletpop.sendFeedback = function() {
	$('#GH_fb_link a, #MPL_Contact').bind('click', function() {
		return fBo('ca_walletpop');
	});
}
// Header promo hover effects
CaWalletpop.rollOverPromo = function() {
	$('.featuredArts > div').each(function(loop) {
		$(this).bind('mouseover', function() {
			$(this).css('background', '#7384d2');
			// var cClass = $('#arrow'+(loop+1)).attr('class');
			$('#arrow'+(loop+1)).removeClass().addClass('ghSprite arrowImg1');
			$('#title'+(loop+1)).css('color', '#ffffff');
		});
		$(this).bind('mouseout', function() {
			$(this).removeAttr('style');
			$('#arrow'+(loop+1)).removeClass().addClass('ghSprite arrowImg');
			$('#title'+(loop+1)).removeAttr('style');
		});
	});
}
// Gallery Carousel code
CaWalletpop.gCarousel = function(){
	$('.galcarousel ul').cycle({'prev':'.previous','next':'.next'});
}
// AFS styles code
CaWalletpop.afsAdjustments = function(){
	this.nr = 'No Results';
	this.nr = this.nr.toLowerCase();
	if($('#center .hub h2').html().indexOf(this.nr) != -1){
		$('#afs_top').addClass('hide');
		$('#afs_bottom').css('margin-top', '1.5em');
	}
}
// AFS styles code
CaWalletpop.mostPopularStories = function(){
	$('#mostPopular ul li').each(function(lt) {
		$(this).removeAttr('class').addClass('horSprite story_'+(lt+1));
	});
}
// Search related
CaWalletpop.searchHandler = function() {
	var defaultText = 'Enter search keywords';
	$('#lemondrop-search').attr('value', defaultText);
	$('#lemondrop-search').bind('focus', function(){$(this).attr('value', '');});
	//if($(this).attr('value') == defaultText){}
	$('#lemondrop-search').blur(function(){
		if(($(this).attr('value') == 'undefined') || (!$(this).attr('value'))){$(this).attr('value', defaultText);}
	});
}
// Replace the link and image - more photo galleries
CaWalletpop.galleryBtnReplace = function() {
	$('img[src$=button_moregalleries.gif]')
	.removeAttr('src')
	.attr('src','http://o.aolcdn.com/art/lemondrop_uk/ld_gallery_button')
	.removeAttr('vspace').removeAttr('hspace');
	$('.articleBody a[href$=/category/picture-galleries-2/], #permalinkBody a[href$=/category/picture-galleries-2/]')
	.removeAttr('href').attr('href','/category/photo-galleries/').attr('title','More photo galleries');
}
// Open all external links in a new window
CaWalletpop.handleExternalLinks = function() {
	// find all links that begin with "http://" and "https://"
	$('a[href^="http://"], a[href^="https://"]').filter(function(){
        // filter out links that have the same domain name as the current page
        return this.hostname && this.hostname !== location.hostname; })
        // add target = "_blank"
        .attr('target', '_blank');
}
// Email form validation
function BS_Form_Validation(){
	var pagename = document.getElementById('whichpage').value;
	document.getElementById('formerrors').style.display = 'none';
	var validName = 0;
	var validEmail = 0;
	var email = document.getElementById('AuthorEmail').value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(trim(document.getElementById('AuthorName').value)){validName = 1;}
	if(filter.test(email)){validEmail = 1;}
	if(pagename == "forward"){
		var validForward = 0;
		var senderEmail = document.getElementById('ForwardEmail').value;
		if(filter.test(senderEmail)){validForward = 1;}
	}
	if(pagename == "tips"){
		var validCom = 0;
		var authorComments = document.getElementById('txtComments').value;
		if(trim(authorComments)){validCom = 1;}
	}
	if(validName == 1 && validEmail == 1 && validForward == 1){return true;}
	if(validName == 1 && validEmail == 1 && validCom == 1){return true;}
	else {
		document.getElementById('formerrors').style.display = 'block';
		var errorMessage = '<p>Errors: </p>';
		if(validName == 0) {errorMessage += '<p>You must provide a name! </p>';}
		if(validEmail == 0) {errorMessage += '<p>E-mail address is not valid!<p>';}
		if(validForward == 0) {errorMessage += '<p>You must enter an e-mail address to send to!</p>';}
		if(validCom == 0) {errorMessage += '<p>You must enter comments!</p>';}
	}
	document.getElementById('formerrors').innerHTML = errorMessage;
	return false;
}
function trim(str){str=str.replace(/^\s+/,'');for(var i=str.length-1;i>=0;i--){if(/\S/.test(str.charAt(i))){str=str.substring(0,i+1);break;}}return str;}
//]]>