//Base script for Especially4Pets_Theme

jQuery(document).ready(function(){
	/*jQuery('#main_nav ul li a').each(function(){
		var tmpname = parseBGImgFromText(jQuery(this).html(),'');
		//alert(tmpname);
		
		if(!jQuery(this).parent().hasClass('current_page_item')){
			jQuery(this).parent().css('background','url('+tmpname+') 0px 0px no-repeat');
		}
		else{
			jQuery(this).parent().css('background','url('+tmpname+') -110px 0px no-repeat');
		}
	});
	jQuery('#main_nav ul li a').mouseover(function(){
		if(!jQuery(this).parent().hasClass('current_page_item')){
			jQuery(this).parent().css('background-position','-110px 0px');
		}
	});
	jQuery('#main_nav ul li a').mouseout(function(){
		if(!jQuery(this).parent().hasClass('current_page_item')){
			jQuery(this).parent().css('background-position','0px 0px');
		}
	});*/
	theRotator();
	//alert(jQuery('div.menu>ul'));
	jQuery('div.menu>ul').addClass('sf-menu');
	jQuery('div.menu>ul').superfish();
});

function parseBGImgFromText(txt,roll){
	txt = txt.replace(/[^A-Za-z0-9]/g,'');
	txt = txt.toLowerCase();
	return "/wp-content/themes/esp4pets/images/"+txt+roll+".png";
}

function theRotator() {
	//Set the opacity of all images to 0
	jQuery('div#header_slideshow ul li').css({opacity: 0.0});
	jQuery('div#quotes_box ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div#header_slideshow ul li:first').css({opacity: 1.0});
	jQuery('div#quotes_box ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',10000);
	setInterval('rotate_phrases()',10000);
}

function rotate() {	
	//Get the first image
	var current = (jQuery('div#header_slideshow ul li.show')?  jQuery('div#header_slideshow ul li.show') : jQuery('div#header_slideshow ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#header_slideshow ul li:first') :current.next()) : jQuery('div#header_slideshow ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function rotate_phrases() {	
	//Get the first image
	var current = (jQuery('div#quotes_box ul li.show')?  jQuery('div#quotes_box ul li.show') : jQuery('div#header_slideshow ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#quotes_box ul li:first') :current.next()) : jQuery('div#quotes_box ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};
