
$(document).ready(function() {	

	//***********************************************
	//Easy slider
	//***********************************************
	$("#banner").easySlider({auto: true, continuous: true, numeric:true, pause:6500, speed:800});


	$("a[rel^='prettyPhoto']").prettyPhoto({
		show_title: false,
		deeplinking: false,
		social_tools: false
	});
	
	
	//Set here states of nested posts
	var url= window.location.href.split("/");
	var urlLength = url.length;
	var newurl = urlLength -3//;
	url= url[newurl];	
	//alert(url);
	if(url == "recipe"){
		$('li#menu-item-629').addClass("current-menu-item");
	}
	if(url == "cookbook"){
		$('li#menu-item-631').addClass("current-menu-item");
	}
	if(url == "video"){
		$('li#menu-item-627').addClass("current-menu-item");
	}
	if(url == "blog" || url == "healthy"  ){
		$('li#menu-item-626').addClass("current-menu-item");
	}
	
	
	//***********************************************
	//MOST RECENT POSTS
	//***********************************************	
	if($('#recent').length){
		$('#tptn_related img').each(function(){
			$(this).addClass('post-image');			 
		});
		
		$('#recent #recent_nav li.recent').addClass('current');
		$('#most-recent').fadeIn();
		
		$('#recent #recent_nav li').click(function(){
			if($(this).hasClass('current')){
			}
			else{
				var selected = $(this);	
				$(this).addClass('current').siblings('li').removeClass('current');
				$('#recent #recent_holder').animate({'opacity': 0}, 'normal', function(){
					if($(selected).hasClass('read')){				
						$('#most-read').show();			
						$('#most-recent').hide();
					}
					if($(selected).hasClass('recent')){		
						$('#most-recent').show();			
						$('#most-read').hide();		
					}
					$(this).animate({'opacity': 1}, 'normal');
				});	
			}
				
		});
	}
	
	//***********************************************
	//SOCIAL MEDIA TABS
	//***********************************************	
	if($('#social_tabs').length){
		
		$('#social_tabs li.fb').addClass('current');
		$('#facebook_box').fadeIn();
		var selected;
		$('#social_tabs li').click(function(){
			if($(this).hasClass('current')){
			}
			else{
			selected = $(this);	
	 		$(this).addClass('current').siblings('li').removeClass('current');
			$('#social_tabs_wrapper').animate({'opacity': 0}, 'normal', function(){
                if($(selected).hasClass('twitter')){				
					$('#tweet').show();			
					$('#facebook_box').hide();
				}
				if($(selected).hasClass('fb')){		
					$('#facebook_box').show();			
					$('#tweet').hide();		
				}
				$(this).animate({'opacity': 1}, 'normal');
            });	
			}
			
		});
		
	}
	
	
	var snav = false;
	var currentIndex = 0;
	var newIndex = 0;
	var pagetitle = document.title;
   	var snavUrl = window.location.hash.slice(2);
	//alert(snavUrl);
	$("#video-listing li").each(function(){
		snav = true;
		if(window.location.hash != null){
			var theHash = $(this).text().replace(/ /g,"-").toLowerCase();						  
			if(snavUrl == theHash){
				currentIndex = $(this).index();	
			}
		
		}
	});		
	
	if(snav)initToggle(currentIndex);
	//show first section!
	$('#video-listing li:nth('+currentIndex+')').addClass("active");	
	
	function initToggle(currentIndex){		
		$('#video-listing li:nth('+currentIndex+')').addClass("active");		
		//Set browser hash
		var page = $('#video-listing li:nth('+currentIndex+')').text().replace(/ /g,"-").toLowerCase();
		window.location.hash = '/'+page;
		document.title = $('#video-listing li:nth('+currentIndex+')').text() + " | " +pagetitle; 
		var selected = $('#video-listing li:nth('+currentIndex+')').attr('id');
		if(selected == 'videos-1'){
			$('#tvshows').fadeOut(function(){
				$('#cookingtips').fadeIn();
			});
		}		
		else if(selected == 'videos-2'){
			$('#cookingtips').fadeOut(function(){	
			$('#tvshows').fadeIn();	
			});	
		}
		else{
			$('#tvshows').fadeIn();
		}
	}
	
	
	//Video Componet
	$('#video-listing li').click(function(evt){						
		var page = $(this).text().replace(/ /g,"-").toLowerCase();
		window.location.hash = '/'+page;	
		$(this).addClass("active").siblings('li').removeClass("active");		
		var selected = $(this).attr('id');
		if(selected == 'videos-1'){
			$('#tvshows').fadeOut(function(){
				$('#cookingtips').fadeIn();
			});
		}		
		else if(selected == 'videos-2'){
			$('#cookingtips').fadeOut(function(){	
			$('#tvshows').fadeIn();	
			});	
		}
	});
	
	
	
	//***********************************************
	//BLOG rollovers
	//***********************************************
	$('a.thumb img').each(function () {	
		var $span = $(this).css('opacity', 1);																																														
		$(this).hover(function () {	
			$span.stop().animate({opacity: 0.8}, 300);
		}, function () {		
			$span.stop().animate({opacity: 1}, 300);				
		});
	});
	
	
	
	//***********************************************
	//TWITTER
	//***********************************************
	$("#tweet").tweet({        
	  avatar_size: 50,
	  count: 4,
	  username: ["janetpodleski", "gretapodleski"],
	  loading_text: "Searching Twitter...",
      refresh_interval: 180
	     }).bind("loaded",function(){$(this).find("a").attr("target","_blank");
	});
	
	$('input#cc_email').val("your email address");
	$("input#cc_email").focus(function(){
		if(this.value == 'your email address'){
			this.value='';					
		}
	});
	$("input#cc_email").blur(function(){
		if(this.value==''){this.value='your email address';}
	});
	//***********************************************
	//Scroll to comments
	//***********************************************
	$('a.scroll').click(function(){//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
		$.scrollTo( this.hash, 700, { easing:'elasout' });
		return false;
	});
	
	
	$.easing.elasout = function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	};	
	//$('div.pane').scrollTo( 0 );//reset all scrollable panes to (0,0)
	//$.scrollTo( 0 );//reset the screen to (0,0)
	
		
		
		
});



