// Search box value remove on focus

var swap_text_boxes = [];

function init_swap_text_boxes(){
  //Store the default value for each box
  $('input[type=text][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=text][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
    }
  });
  $('input[type=text][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
    }
  });

}

// Preload images

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}


//
//     JQuery Text resize + Cookie recall
//     by Jonny Kamaly
//     based on script written by Faisal & Homar
//
 
function getWindowWidth(){
	var de = document.documentElement;
	return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};  

function ieFontSize(){
		return (parseFloat($('html').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
	};  
function getFontSize(){
	if($.browser.msie && (parseFloat($('html').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0){
		//alert("Real font size is: " + ieFontSize());
		return ieFontSize();
	}else{
		return $("html").css("font-size");
	}
}


var sitefunctions = {
	textresize : function(){
		// show text resizing links
		
		var $cookie_name = "ar-fontsize";
		var originalFontSize = getFontSize();
		// 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
		} else {
			$.cookie($cookie_name, originalFontSize);
		}
		$("#increaseFont").bind("click", function() {
		  var currentFontSize = getFontSize();
		  var currentFontSizeNum = parseFloat(currentFontSize);
		  var newFontSize = currentFontSizeNum + 2;
		  $("html").css("font-size", newFontSize);
		  $.cookie($cookie_name, newFontSize);
		
		  return false;
		});
		$("#decreaseFont").bind("click", function() {
		  var currentFontSize = getFontSize();
		  var currentFontSizeNum = parseFloat(currentFontSize);
		  var newFontSize = currentFontSizeNum - 2;
		  if(newFontSize >= parseFloat(originalFontSize)){
		  		$("html").css("font-size", newFontSize);
		  		$.cookie($cookie_name, newFontSize);
			}
		  return false;
		});
	}
}
 


$(document).ready(function(){ 
	// preload images
	$.preloadImages("assets/images/site/prevBtn_hover.png", "assets/images/site/nextBtn_up.png");

	init_swap_text_boxes();
	
	sitefunctions.textresize();
	
	/* Keep document valid and use this function to open all external links containing http */	
	$('a[href^=http]').click( function() {
        window.open(this.href);
        return false;
    });

	
	/* Easy Slider */
	$("#slider").easySlider();
	$("#nextBtn").hover(
	  function () {$(this).css("background-image","url(assets/images/site/nextBtn_hover.png)").css('cursor','pointer'); }, 
	  function () {$(this).css("background-image","url(assets/images/site/nextBtn_hover.png)");});
	$("#prevBtn").hover(
	  function () {$(this).css("background-image","url(assets/images/site/prevBtn_hover.png)").css('cursor','pointer'); }, 
	  function () {$(this).css("background-image","url(assets/images/site/prevBtn_hover.png)");});
	$("#nextBtn,#prevBtn").click(function () { 
		$(this).css("cursor","pointer");
		return false;
	});
	/* // Easy Slider */
	
}); 


