
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie( name, value, expires, path, domain, secure )
{
    //alert('setCookie');
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
    expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    var docCookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );

    //alert('docCookie:'+docCookie);
    document.cookie = docCookie;
}

/*parsing url parameters*/
var re = /&/;
var param1;

var eleParam, varName, name, typetName;

function passParam(){
	if(param1){
	    var urlPath = param1.split("?")
		var parseparam = urlPath[1].split(re);
	}
	if(parseparam){
	  $(parseparam).each(function(i,ele){
		  eleParam = ele.split("=");
		  varName = eleParam[0];
		  name = eleParam[1]
		  if(varName == "type"){ typetName = name; }
		});
	   return typetName;
	}
}
/*end - parsing*/

/*resize flicker image*/
function resize(which, max) {
  var elem = document.getElementById(which);
  if (elem == undefined || elem == null) return false;
  if (max == undefined) max = 100;
  if (elem.width > elem.height) {
    if (elem.width > max) elem.width = max;
  } else {
    if (elem.height > max) elem.height = max;
  }
}

var findHoverStateImgs = $('img.hover');
if(findHoverStateImgs){
	findHoverStateImgs.each(function(i, imgItem) {
		var imgSRC = $(imgItem).attr('src');
		/*preloader*/
		$(imgItem).attr('src', imgSRC.replace(/\.(.+)$/i, "_on.$1"));
		$(imgItem).attr('src', imgSRC.replace(/_on\.(.+)$/i, ".$1"));
		var findActive = $(imgItem).hasClass('active');
		if(findActive){ $(imgItem).attr('src', imgSRC.replace(/\.jpg/i, "_on.jpg")) }//if condition
	}); //end imgItem.each
}


var intervalId = 0;
var stories;
var num = 0;

var refreshIntervalId = setInterval ( "rotateLgFeatured(stories)", 10000 );

function setIntervalAnimationTime(){
    refreshIntervalId = setInterval("rotateLgFeatured(stories)", 10000);
}
function clearIntervalAnimationTime(){
	clearInterval(refreshIntervalId);
}

/*featured stories section*/
function rotateLgFeatured(stories)
{	
    var maxStories = 3;
    if (currentTopicPage == "pepsimax") {
        maxStories = 3;
    }
    if (currentTopicPage == "everything") {
        maxStories = 2;
    }

	if (stories == null){ stories = num; }
	var numOfStories = $('.rotate-featured img').length;
    if (currentTopicPage == "everything") {
        numOfStories = 3;
    }

	if(stories < numOfStories){
		$('.rotate-featured img:lt('+maxStories+')').each(function(r,img){
			var thisImgSrc = $(img).attr('src');
			if (thisImgSrc.match(/_on\.jpg/i) && !$(img).hasClass('active')) {
				$(img).attr('src', thisImgSrc.replace(/_on.jpg/i, ".jpg"));
			}
		});//change to off
		
		/*if(stories < (numOfStories-1)){
		    var thisImg = $('.rotate-featured img').eq(stories);
		    var thisImgSrc = $('.rotate-featured img').eq(stories).attr('src');
			if (!thisImgSrc.match(/_on\.(.+)$/i)){
				$(thisImg).attr('src', thisImgSrc.replace(/\.jpg/i, "_on.jpg"));
			}
		}//change to on*/
		
		var slidePosition = (stories+1) * 690;
		if(stories == maxStories){
			var slidePosition = 0;
			$('.featured .lg_featured .slide-container').stop().animate({left:"-"+slidePosition+"px"}, { easing:"swing" });
		} else {
			$('.slide-container').stop().animate({left:"-"+slidePosition+"px"}, {easing:"swing"});
		}
	} 
	if(stories == numOfStories){ num = -1; }
	num = num + 1;
}
/*end - featured stories section*/

$(document).ready(function(){

	/*featured stories section*/
	$(".rotate-featured img").click(function(e){
	
    	// turn everything off
		$('.rotate-featured img').each(function(r,img){
            
			$(img).removeClass('active');
			var thisImgSrc = $(img).attr('src');
			if (thisImgSrc.match(/_on\.jpg/i)) {
				$(img).attr('src', thisImgSrc.replace(/_on.jpg/i, ".jpg"));
			}
		});

	    // turn the selected one on
		$(this).attr('src', $(this).attr('src').replace(/.jpg/i, "_on.jpg"));
		$(this).addClass('active');
		
		/*$(".rotate-featured img").each(function(j,ele){
			if( j != 3 ){
				if($(ele).hasClass('active')){
				    //clearInterval(refreshIntervalId); rotateLgFeatured(j);
                }
			}
		})*/
    });
	/*end*/
						   
	/*nav-landing*/
	var landingnav = $(".landing-nav-container .topic");
	var landingPage = $().find(".landing-nav-container .topic").length;
	if (landingPage = 1){
		if($(landingnav).find("div.tips").length == 0){ $(landingnav).append("<div class='tips'></div>"); }
		$(landingnav).find("div.tips").animate({opacity: "show", top: "-155"}, "slow");
		var hoverText = $(landingnav).attr("title");
		$(landingnav).find("div.tips").html(hoverText);
		$(landingnav).attr("title","");
	}
	/*end - nav-landing*/

    /* DEBUG ONLY: Force nav container open */
//	var getListHeight = ($('.nav-container .nav-topics li').length * 36) + 50;
//	$('.nav-container .nav-topics').css({zIndex:'30000'});
//	$('.hiderContainer').css({height: getListHeight+"px", top: '60px'});
//	$(".nav-topics").css({marginTop:'0px'});
//    // custom line for allowing flyout to show (can we do this w overflow?)
//	$('.hiderContainer').css({width: '500px'});
	/* DEBUG END */

	
	$(".nav-container .topic, .nav-container .topicmax").hover(
		function () {
			var getListHeight = ($('.nav-container .nav-topics li').length * 36) + ($('#submenu div').length * 20);
			$('.nav-container .nav-topics').css({zIndex:'30000'});
			$('.hiderContainer').css({height: getListHeight+"px", top: '60px'});
			$(".nav-topics").css({marginTop:'0px'});
            // custom line for allowing flyout to show (can we do this w overflow?)
            $('.hiderContainer').css({width: '500px'});
			//$(".nav-topics").stop().animate({marginTop:'0px'}, 700);
		}, 
		function () {
			$('.nav-container .nav-topics').css({zIndex:''});
			$(".nav-topics").css({marginTop:'-400px'});
			$('.hiderContainer').css({top: '-9000px'});
			toggleSubMenu('out');
		}
	);
	/*end - nav-topic*/
	
	/*tool tip*/
	$(".twitter-container").append("<div class='tips'></div>");

	$(".add-tip a").hover(
		function () {
			$(".twitter-container").find("div.tips").animate({opacity: "show", top: "-15"}, 200);
			var hoverText = $(this).attr("title");
			$(".twitter-container").find("div.tips").html(hoverText);
			$(this).attr("title","");
		}, 
		function () {
			/*out*/
			var tipTitle = $().find("div.tips").html();
			$(this).attr("title", tipTitle);
			$(".twitter-container").find("div.tips").animate({opacity: "hide", top: "-55"}, 100);
		}
	);
	/*end - tool tip*/
	
	/*crop image to custom size*/
	if($().find("img.flickr-resize")[0] != null){
		$("img.yt-resize").crop(156, 207);
		$("img.flickr-resize").crop(150, 208);
	}
	/*end - resize*/
	
	$(".add-description").hover(
		function () { 
				$(this).find('.info').stop().show().animate({marginBottom:'78px'}, 600);
		}, 
		function () {
			$(this).find('.info').stop().animate({marginBottom:'-148px'}, 600);
		}
	);
	
	/*resizing window - ie hack*/
	function content_resize() {
		var w = $( window );
		var findTB_window = $().find('#TB_window');
		if($().find('#TB_window').length) {tb_position() }
	}
	if($().find('#TB_window').length) {
	    ( '#TB_window' ).resize( content_resize );
	    }
	content_resize();
	/*end*/

}); //main - styles effect documentt

