//Handle Kentico JQuery Object.
var $j;

$(document).ready(function() {	
	//Store JQuery in object Kentico expects for User Contribution web part
	$j = $;	


	/*kentico BizForm apply this class to the image submit button*/
	$(".FormButton").hover(
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_on", "_off"));
	  }
	);
	/*you can apply this class to image buttons so they will have rollover effections*/
	$(".ImageButton").hover(
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_on", "_off"));
	  }
	);
	
	/* font size */
	// Reset Font Size	
	var minFontSize = 12;
	var maxFontSize = 20;
	var originalFontSize = $('html').css('font-size'); /*16px*/
	$(".resetFont").click(function(){
		$('html').css('font-size', originalFontSize);
		return false;
	});
	// Increase Font Size
	$(".increaseFont").click(function(){
		/*var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*1.2;
		if (newFontSize <= maxFontSize) {
			$('html').css('font-size', newFontSize);
		}
		else {
			$('html').css('font-size', maxFontSize);
		}*/
		$('html').css('font-size', maxFontSize);
		return false;
	});
	// Decrease Font Size
	$(".decreaseFont").click(function(){
		/*var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		var newFontSize = currentFontSizeNum*0.8;
		if (minFontSize <= newFontSize) {
			$('html').css('font-size', newFontSize);
		}
		else {
			$('html').css('font-size', minFontSize);
		}*/
		$('html').css('font-size', minFontSize);
		return false;
	});
	if($('html').css('font-size')=="16px") {		
		$(".resetFont img").addClass("here");
		$(".resetFont img").attr("src",$(".resetFont img").attr("src").replace("_off", "_on"));
	}
	
	/* Join/login Button */
	$("#btnJoin").click(function (e) {
        e.preventDefault(); 
        $("#joinLoginForm").slideToggle("slow");
		return false;
    });
	
	
	/* navMain js hover, on state*/
	$("#menuElem img").hover(
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_on", "_off"));
	  }
	);
	
	/* Branding Nav hover: font size, language, about, Subscribe, Support links on the top */ 
	$(".decreaseFont img").click(function() {
	 	$(this).addClass("here");
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
		$(".increaseFont img").attr("src",$(".increaseFont img").attr("src").replace("_on", "_off"));
		$(".increaseFont img").removeClass("here");
		$(".resetFont img").attr("src",$(".resetFont img").attr("src").replace("_on", "_off"));
		$(".resetFont img").removeClass("here");
	});
	$(".decreaseFont img").hover(								 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		if($(".decreaseFont img").attr("class") == "here") {
			//do nothing
		} else {
			$(this).attr("src",$(this).attr("src").replace("_on", "_off"));	
		}
	  }
	);
	
	$(".resetFont img").click(function() {
	 	$(this).addClass("here");	
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
		$(".decreaseFont img").attr("src",$(".decreaseFont img").attr("src").replace("_on", "_off"));
		$(".decreaseFont img").removeClass("here");
		$(".increaseFont img").attr("src",$(".increaseFont img").attr("src").replace("_on", "_off"));
		$(".increaseFont img").removeClass("here");
	});
	$(".resetFont img").hover(								 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		if($(".resetFont img").attr("class") == "here") {
			//do nothing
		} else {
			$(this).attr("src",$(this).attr("src").replace("_on", "_off"));	
		}
	  }
	);
	
	$(".increaseFont img").click(function() {
	 	$(this).addClass("here");	  
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
		$(".decreaseFont img").attr("src",$(".decreaseFont img").attr("src").replace("_on", "_off"));
		$(".decreaseFont img").removeClass("here");
		$(".resetFont img").attr("src",$(".resetFont img").attr("src").replace("_on", "_off"));
		$(".resetFont img").removeClass("here");
	});
	$(".increaseFont img").hover(								 
	  function () {
		$(this).attr("src",$(this).attr("src").replace("_off", "_on"));
	  }, 
	  function () {
		if($(".increaseFont img").attr("class") == "here") {
			//do nothing
		} else {
			$(this).attr("src",$(this).attr("src").replace("_on", "_off"));	
		}
	  }
	);
	
	/*Email Scrambling*/
	$('.ch-safe-email').each(function(){
	    var mailbits = $(this).attr('href').split('@');
	    var mailto = "mailto:" + $(this).attr('title') + "@" + mailbits[1];
	    $(this).attr('title', '');
	    $(this).attr('href', mailto);
	});
		
    /*Bio show-hide*/   		    
    $(".ReadBio").click(function (e) {
        e.preventDefault(); 
        $(".pane").toggle("slow");
    });  
    
    /*Membership - Already a member?*/   		    
    $("#showLogin").click(function (e) {
        e.preventDefault(); 
        $("#joinLoginForm").slideToggle("slow");
		return false;
    });

    /*Blog Comment Login Prompt*/
    $(".btnBlogLoginPrompt").click(function(e) {
        e.preventDefault();
        $("#joinLoginForm").slideToggle("slow");
        
        //code to move to the page
        $('html, body').animate({ scrollTop: 0 }, 'slow');

        return false;
    }); 
    
    /*Generic Page Login Prompt*/
    $(".btnScrollUpLogin").click(function(e) {
        e.preventDefault();
        $("#joinLoginForm").slideToggle("slow");
        
        //code to move to the page
        $('html, body').animate({ scrollTop: 0 }, 'slow');

        return false;
    }); 
		
});

function lightboxJump(newLocation, isInternal){
    if(isInternal == true){
        window.location = newLocation;
    }
    else{
        window.open(newLocation);
    }
}

function toggleLang(href){
	pageTracker._link(href);
	window.location = href;
}