var sitefunctions = {
    textresize : function(){
        // show text resizing links
        $("#zoomer").css("display", "block");
        $(".FontSize").css("visibility", "visible");
       // console.log("resize");
        var $cookie_name = "sitename-FontSize";
        var originalFontSize = $("html").css("font-size");
        // if exists load saved value, otherwise store it
        if($.cookie($cookie_name)) {
            var $getSize = $.cookie($cookie_name);
            $("html").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error
            var currentFontSize = $("html").css("font-size");
            var currentFontSizeNum = parseFloat(currentFontSize, 10);
            if(currentFontSizeNum > 16){
            	$(".FontSizeDec img.fs_icon").attr("src", "/images/zoom_down.gif");
            	addFontSiteDecListener();
            }
        } else {
            $.cookie($cookie_name, originalFontSize, {path: '/'});
        }
         // Decrease Font Size
       
         
        addFontSiteIncListener();
       
    }
}
 

function addFontSiteIncListener(){
    $(".FontSizeInc").bind("click", function() {
    	var $cookie_name = "sitename-FontSize";
    	var originalFontSize = $("html").css("font-size");
        var currentFontSize = $("html").css("font-size");
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum+1;
        newFontSize = parseInt(newFontSize, 10);
        if (newFontSize) {
            $("html").css("font-size", newFontSize);
            $.cookie($cookie_name, newFontSize, {path: '/'});
        }
        checkFontDecrease("inc");
        return false;   
    });
    
	 $(".FontSizeInc").hover (
			 function(){
				 $(".FontSizeInc .hover_tip").show();
			 },
			 function(){
				 $(".FontSizeInc .hover_tip").hide();
			 }
	 );	    
}

function addFontSiteDecListener(){
    $(".FontSizeDec").bind("click",function(){
    	
    	var $cookie_name = "sitename-FontSize";
    	var originalFontSize = $("html").css("font-size");
        var currentFontSize = $('html').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = currentFontSizeNum-1;
        newFontSize = parseInt(newFontSize, 10);
        if (newFontSize) {
            $("html").css("font-size", newFontSize);
            $.cookie($cookie_name, newFontSize, {path: '/'});
        }
        checkFontDecrease("dec");
        return false;
      });
    
	 $(".FontSizeDec").bind ("mouseover",
			 function(){
		 		$(".FontSizeDec .hover_tip").show();
			 }		
	 				 ).bind("mouseout", 
			 function(){
				 $(".FontSizeDec .hover_tip").hide();
			 }
	 );    
}


function removeFontSiteDecListener(){
	 $(".FontSizeDec").unbind("click");
	 $(".FontSizeDec").unbind('mouseover').unbind('mouseout');
	 $(".FontSizeDec .hover_tip").hide();
	  
}	
function removeFontSiteIncListener(){
	$(".FontSizeInc").unbind("click");
	$(".FontSizeInc").unbind('mouseover').unbind('mouseout');
}



function checkFontDecrease(from){
	var currentFontSize = $("html").css("font-size");
    var currentFontSizeNum = parseFloat(currentFontSize, 10);
    if(currentFontSizeNum == 17 && from == "inc"){
    	$(".FontSizeDec img.fs_icon").attr("src", "/images/zoom_down.gif");
    	addFontSiteDecListener();
    	
    	//console.log("show"+currentFontSizeNum);
    }else if(currentFontSizeNum == 16){
    	$(".FontSizeDec img.fs_icon").attr("src", "/images/zoom_down_deact.gif");
    	removeFontSiteDecListener();
    	
    	//console.log("hide"+currentFontSizeNum);
    }
}




$(document).ready(function(){
     sitefunctions.textresize(); 
})

