//<![CDATA[
    /*  
    	File:lemondrop-uk-functions.js    	
	Author: Lokesh Shetty
	Date: 04/11/2009
	Revision: 1	
	Description : JS Methods to handle custom actions
	(c) Copyright 2008 AOL LLC	
	Dependencies : JQuery 1.3.2
    	Attached on Document Ready
    */

if (!lemondropUKEffects) {var lemondropUKEffects = {};};
// Category highlight
lemondropUKEffects.selectedCategory = function(c) {
	if(!c) c = "main";
	$('#cat-'+c+' > a').addClass('catSelected');
}
// Handle first, last and even elements
lemondropUKEffects.documentAdjust = function() {
	$("ul li:first-child").addClass("first");
	// $("ul li:odd").addClass("odd");
	$("ul li:even").addClass("even");
	$("ul li:last-child").addClass("last");
}
// Category drop down controls
lemondropUKEffects.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
lemondropUKEffects.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
lemondropUKEffects.sendFeedback = function() {
	$('#categoryNav ul[class=second] li a, #footerCFF, #contactUs').bind('click', function() {
		return fBo('uk_lemondrop'); // from feedback1.js
	});	
}
// Header promo hover effects
lemondropUKEffects.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
lemondropUKEffects.gCarousel = function(){
	$('.galcarousel ul').cycle({'prev':'.previous','next':'.next'});
}
// AFS styles code
lemondropUKEffects.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
lemondropUKEffects.mostPopularStories = function(){
	$('#mostPopular ul li').each(function(lt) {
		$(this).removeAttr('class').addClass('horSprite story_'+(lt+1));
	});
}
// Search related
lemondropUKEffects.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
lemondropUKEffects.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
lemondropUKEffects.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');
}
// Agony aunt form validation
function agonyAuntFormValidation(){
	document.getElementById('formerrors').style.display='none';
	var validName=false;
	var validEmail=false;
	var validCom=false;
	var email=document.getElementById('AuthorEmail').value;
	var author=document.getElementById('AuthorName').value;
	var authorComments=document.getElementById('txtComments').value;
	var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(trim(author)){validName=1;}
	if(filter.test(email)){validEmail=1;}
	if(trim(authorComments)){validCom=1;}
	if(validName && validEmail && validCom){return true;} 
	else {
		document.getElementById('formerrors').style.display='block';
		var errorMessage='<p>Errors: </p>';
		if(!validName){errorMessage+='<p>You must provide a name!</p>';}
		if(!validEmail){errorMessage+='<p>E-mail address is not valid!<p>';}
		if(!validCom){errorMessage+='<p>You must enter comments!</p>';}
		document.getElementById('formerrors').innerHTML=errorMessage;
		return false;
	}
}
// Email form validation
function forwardEmailValidation(){
	document.getElementById('formerrors').style.display = 'none';
	var validName = 0;
	var validEmail = 0;
	var validForward = 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(trim(document.getElementById('ForwardEmail').value)){
		validForward = 1;
	}
	if(validName == 1 && validEmail == 1 && validForward == 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>';
	}
	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;
}
//]]>