var ord = Math.floor(Math.random()*999999999999999999);
function setCookie(){
	if (document.cookie.length>0) {
		tc_start=document.cookie.indexOf("totalvisits=");
		if (tc_start == -1) {
			var texdate=new Date();
			var texpiredays=10000;
			var tcurrentdate=new Date();
			texdate.setDate(texdate.getDate()+texpiredays);
			tcurrentdate.setDate(tcurrentdate.getDate());
			document.cookie="totalvisits=1;expires="+texdate.toGMTString();
		} else {
			var texdate=new Date();
			var texpiredays=10000;
			var tcurrentdate=new Date();
			texdate.setDate(texdate.getDate()+texpiredays);
			tcurrentdate.setDate(tcurrentdate.getDate());

			tc_start = tc_start + 12;
			tc_end = document.cookie.indexOf(";",tc_start);
			if (tc_end==-1) tc_end=document.cookie.length;
			
    		num_visits = Number(unescape(document.cookie.substring(tc_start,tc_end)));
    		num_visits = num_visits + 1;
    		document.cookie="totalvisits=" + num_visits + ";expires="+texdate.toGMTString();
    	}
		
		c_start=document.cookie.indexOf("firstvisit=");
		if (c_start == -1) {
			var exdate=new Date();
			var expiredays=10000;
			var currentdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			currentdate.setDate(currentdate.getDate());
			document.cookie="firstvisit="+currentdate.toGMTString() + ";expires="+exdate.toGMTString();
			document.cookie="totalvisits=1;expires="+exdate.toGMTString();
		}
	}
	var exdate=new Date();
	var expiredays=10000;
	var currentdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	currentdate.setDate(currentdate.getDate());
	document.cookie="lastvisit="+currentdate.toGMTString() + ";expires="+exdate.toGMTString();
}
setCookie();
$(document).ready(function(){

	$("#news_menu").mouseover(function() {
		$("#news_submenu").show();
	});
	
	$("#news_menu").mouseout(function() {
		$("#news_submenu").hide();
	});
	
	$("#ae_menu").mouseover(function() {
		$("#ae_submenu").show();
	});
	
	$("#ae_menu").mouseout(function() {
		$("#ae_submenu").hide();
	});
	
	$("#most_read_link a").css("color","#9fa1a4");
	$("#most_read_link").click(function(){
		$("#shared").hide();
		$("#printed").hide();
		$("#emailed").hide();
		$("#most_read").show();
		$("#most_read_link a").css("color","#9fa1a4");
		$("#shared_link a").css("color","#3582a6");
		$("#printed_link a").css("color","#3582a6");
		$("#emailed_link a").css("color","#3582a6");
	});
	$("#shared_link").click(function(){
		$("#printed").hide();
		$("#emailed").hide();
		$("#most_read").hide();
		$("#shared").show();
		$("#shared_link a").css("color","#9fa1a4");
		$("#most_read_link a").css("color","#3582a6");
		$("#printed_link a").css("color","#3582a6");
		$("#emailed_link a").css("color","#3582a6");
	});
	$("#printed_link").click(function(){
		$("#shared").hide();
		$("#emailed").hide();
		$("#most_read").hide();
		$("#printed").show();
		$("#printed_link a").css("color","#9fa1a4");
		$("#shared_link a").css("color","#3582a6");
		$("#most_read_link a").css("color","#3582a6");
		$("#emailed_link a").css("color","#3582a6");
	});
	$("#emailed_link").click(function(){
		$("#shared").hide();
		$("#printed").hide();
		$("#most_read").hide();
		$("#emailed").show();
		$("#emailed_link a").css("color","#9fa1a4");
		$("#shared_link a").css("color","#3582a6");
		$("#printed_link a").css("color","#3582a6");
		$("#most_read_link a").css("color","#3582a6");
	});
	
	$(function() {
		$(".carousel").jCarouselLite({
			btnNext: ".next",
			btnPrev: ".prev",
			visible: 5
		});
		
	});
	/* Hide Comments function */
	var displayCommentsValue = 5;
	if($(".commentlist .comment").length > displayCommentsValue){
		$("#comment-toggle").show();
		var sliceEnd = $(".commentlist .comment").length - displayCommentsValue;
		$(".commentlist .comment").slice(0,sliceEnd).addClass('hide-comment');
		$(".commentlist .hide-comment").hide();
		$("#comment-toggle").text("Showing "+displayCommentsValue+" recent comments. View all comments.");
		$("#comment-toggle").toggle(
			function(){
				$(this).text("Hide the comments.");
				$(".commentlist .hide-comment").fadeIn("slow");						  
			},
			function(){
				$(this).text("Showing "+displayCommentsValue+" recent comments. View all comments.");
				$(".commentlist .hide-comment").fadeOut("slow");						  
			}
		);
	};
	/* TABS RADIO SWITCH START */
	// Hide all tab content, then show the first one
	$('.tab-radio .tab-content').hide();
	var TabSetCounter = $('.tab-radio').length;
	for(z=0;z<TabSetCounter;z++){
		$('.tab-radio').eq(z).find('.tab:first').addClass('active');
		$('.tab-radio').eq(z).find('.tab-content:first').fadeIn('slow');
		//console.log(z+' '+$('.tab-radio').eq(z).find('.tab:first').html());
	};
	// Function when tab toggle is clicked
	$('.tab-radio .tab').click(function(){
		if($(this).hasClass('active')){
			return;
		}else{
			var ThisTabSet = $(this).parents('.tab-radio');
			$(this).siblings('.tab').removeClass('active');
			$(this).removeClass('hover');
			$(this).addClass('active');
			ThisTabSet.find('.tab-content').hide();
			ThisTabSet.find('.tab-content').eq(ThisTabSet.find('.tab').index(this)).fadeIn("slow");	
			console.log(ThisTabSet.find('.tab').index(this));
		};
	});
	// Hover Extension Class added
	$('.tab-radio .tab').hover(
		function(){
			if($(this).hasClass('active')){
				return;
			}else{
				$(this).addClass('hover');
			};
		},
		function(){
			$(this).removeClass('hover');
		}
	);
	/* TABS RADIO SWITCH END */
	/* Add Hover Class to CTA Objects */
	$('input.cta').hover(
		function(){
		//alert('hover');
		},
		function(){
		//alert('hover off');
		}
	);
	/* Drop Down Nav function */
	$(".drop-down").hover(
		function(){
		//console.log('active roll');
		var box1 = $(this).outerWidth();
		var box2 = $(this).children("ul,ol").width();
		//console.log(box1+" "+box2);
		if(box1 > box2){
			$(this).children("ul,ol").width(box1);
		}
		$(this).addClass('drop-down-active');
		$(this).children("ul,ol").show();
		},
		function(){
		//console.log('active roll out');
		$(this).removeClass('drop-down-active');
		$(this).children("ul,ol").hide();
		}
	);
	/* CHANGE TEXT SIZE START */
	$('.text-size').toggle(
		function(){
			// Resize to 15px
			$('.text-resize').css('font-size','1.25em');
			$('.text-noresize').css('font-size','0.8em');
			//console.log($('.text-resize-jsa').css('font-size'))  
		},
		function(){
			// Resize to 17px
			$('.text-resize').css('font-size','1.416em');
			$('.text-noresize').css('font-size','0.705em');
			//console.log($('.text-resize-jsa').css('font-size'))  
		},
		function(){
			// Original 12px
			$('.text-resize').css('font-size','1em');
			$('.text-noresize').css('font-size','1em');
			//console.log($('.text-resize-jsa').css('font-size'))  
		}
	);
	/* CHANGE TEXT SIZE END */
	/* ANCHOR ANIMATE */
	$("a.anchorSlide").anchorAnimate()
});
function addBookmark(title, url) {
	if (window.sidebar) { // Firefox
		window.sidebar.addPanel(title, url, '');
	} else if (window.opera) { // Opera
		var a = document.createElement('A');
		a.rel = 'sidebar';
		a.target = '_search';
		a.title = title;
		a.href = url;
		a.click();
	} else if (document.all) { // IE
		window.external.AddFavorite(url, title);
	}
}
/*******
	***	Anchor Slider by Cedric Dugas   ***
	*** Http://www.position-absolute.com ***	
*****/
jQuery.fn.anchorAnimate = function(settings) {
 	settings = jQuery.extend({
		speed : 1100
	}, settings);	
	return this.each(function(){
		var caller = this
		$(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = $(caller).attr("href")
			
			var destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}