$(document).ready(function() {
			
	$(function() {
		$("a[rel='_blank']").attr("target","_blank");				
	});

	$(function() {
		$("input, select, textarea").each(function(){
		  $(this).attr("name",$(this).attr("id"));
		});				
	});

			
	$("a[rel='_back']").click(function(){
		history.back();
		return false
	});
	
	$('a.scrollTop').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
		return false
	});
	
	$.urlParam = function(name){
		var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
		if(results) {
			return results[1] || 0;
		}
	};
	
	jQuery.fn.delay = function(time,func){
		this.each(function(){
			setTimeout(func,time);
		});	
	return this;
	};
	
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
    	return this.animate({opacity: 'toggle'}, speed, easing, callback);
	}; 
	
	$("a.anchor-link").anchorAnimate();	
		
});

function in_array(thaArray, element){
 var res=false;
  for(var e=0;e<thaArray.length;e++){
     if(thaArray[e] == element){
       res=true;
       break;
     }
   }
 return res;
}

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;
		})
	})
}

function cookieResize(selector, defaultSize) {
    var lastSize = defaultSize;
    function write(name, value, days) {
        var expires = "";
    	if (days) {
      		var date = new Date();
      		date.setTime(date.getTime() + (days * 86400000));
      		var expires = "; expires=" + date.toGMTString();
     	}
     	document.cookie = name + "=" + value + expires + "; path=/";
    }
	function read(name) {
     	name += "=";
     	var ca = document.cookie.split(';');
     	for(var i = 0; i < ca.length; i++) {
      		var c = ca[i];
      		while (c.charAt(0) == ' ') c = c.substring(1, c.length);
      		if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
     	}
     	return null;
    }
	function updateSizeFromCookie() {
        $('body').removeClass(lastSize);
        lastSize = read('size') || defaultSize;
        $('body').addClass(lastSize);
    }
    jQuery(selector).click(function() {
        write('size', this.className);
        updateSizeFromCookie();
        return false;
    });
	updateSizeFromCookie();    
}
