var settings = "";
Shadowbox.init({ skipSetup: true });

$(document).ready(function(){
	/** Fetch site settings. */
	 $.get("/wp-content/plugins/perfectbound/xml.php", { action: "settings" }, function(data){
		settings = eval(data); deliverInterstitial(settings); 
		}, "json");
		
	/** Navigation Animations */
	$('.inactive_nav').hover(
		function () {
			/* Turn off our active navigation */
			$anav = $(".active_nav"); 
			$anav.removeClass("active_nav");
			$anav.addClass("inactive_nav");
			
			$(this).removeClass("inactive_nav");
			$(this).addClass("active_nav");
		},
		function () {
			$(this).removeClass("active_nav");
			$(this).addClass("inactive_nav");
			/* Switch back to the active navigation element */
			$anav.removeClass("inactive_nav");
			$anav.addClass("active_nav");
		}
	);
	
	/** Search Input Handling */
	$("#query").click(function() {
		if ( $(this).val() == 'Search Linux Magazine' ) {
			$(this).val('');
			$(this).css( 'color', '#000' ); 
		}
	});

	/** Social Media "Follow" Button Rollovers */
	$(".socmed_ico").mouseover(function() {
		$('#socmed_msg').html( $(this).find('img').attr("alt") );
	}).mouseout(function(){
		$('#socmed_msg').html( "Follow Linux Magazine" );
	});	
});


function deliverInterstitial(config) {
	if(config.interstitialActive=='true'&&!Get_Cookie(config.interstitialCookie)) {
		Shadowbox.open({
		        content:    	'<script type="text/javascript">GA_googleFillSlot("LinuxMagazine_ROS_640x480_North");<\/script>',
		        player:     	"html",
		        title:      	"Visit this Linux Magazine Sponsor.",
		        height:     	480,
		        width:      	640, 
				options:   { 
							modal: 			true,
							overlayOpacity: .98, 
							onOpen: 		function(){ $("[id^=banner]").hide(); Set_Cookie(config.interstitialCookie,window.location,config.interstitialReset,'/','',''); },
							onClose: 		function(){ $("[id^=banner]").show(); } 
		    			}
		});
	}
}

function Get_Cookie(check_name){
var a_all_cookies=document.cookie.split(';');
var a_temp_cookie='';
var cookie_name='';
var cookie_value='';
var b_cookie_found=false;
	for(i=0; i<a_all_cookies.length; i++) {

		a_temp_cookie=a_all_cookies[i].split('=');
		cookie_name=a_temp_cookie[0].replace(/^\s+|\s+$/g,'');
		if(cookie_name==check_name){b_cookie_found=true;
		if(a_temp_cookie.length>1){cookie_value=unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g,''))} 
		return cookie_value;
		break;

	}
	a_temp_cookie=null;
	cookie_name=''} 
	if(!b_cookie_found){return null} 
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// 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;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
