var Site = function() {
 $(document).ready(function(){

	$("div.side div.box").setTabs();
	$("div.header2 div.intesa").headerDropdown({},"init");
	$(".tools .scroll").scrollable({
		size: 6,
		items: 'ul',
		prev: '.scrollLeft',
		next: '.scrollRight',
		disabledClassPrev: 'disabledLeft',
		disabledClassNext: 'disabledRight',
		speed: 150,
		easing: 'swing',
		clickable: false
	});

	$('div.tabsheet div.tabs div.tab').click(function() {
		$(this).parents('div.tabsheet').removeClass('ts1').removeClass('ts2').removeClass('ts3').removeClass('ts4');
		$(this).parents('div.tabsheet').addClass('ts' + this.className.split(' tab')[1]);
		this.blur();
		return false;
	});
	
 });
}();

$.fn.extend({

	setTabs: function(o) {
		o = $.extend({
			tabs: 't',
			boxes: 'b',
			boxesTag: 'ul'
		},o);
		var cont = $(this),b,c;
		
		cont.find("div."+o.tabs+" a").each(function(){
			$(this).click(function(){
				if (!$(this).hasClass("active")) {
					c = $(this).attr("rel"); // clicked
					$(this).parent().find("a").each(function(){
						b = $(this).attr("rel");
						if ($(this).hasClass("active")) {
							$(this).removeClass("active").removeClass(b+"Active");
							//cont.find(o.boxesTag+"."+b).removeClass("active");
						} else if (b==c) {
							$(this).addClass("active").addClass(b+"Active");
							//cont.find(o.boxesTag+"."+b).addClass("active");
						}
					});
					
				}
				this.blur();
				return false;
			});
		});
		
	},
	
	headerDropdown: function(o,m) {
		o = $.extend({
			tgl: 'tgl',
			bottomli: 'bottom',
			dropdown: 'dropdown',
			dropdownBottom: 6
		},o);
		var $dropdown = $(this).find("div."+o.dropdown),
			$tgl = $(this).find("div."+o.tgl),
			$bottomLi = $(this).find("li."+o.bottomli),
			dropdownHeight = $dropdown.height(),
			tglHeight = $tgl.height(),
			tglTop = $tgl.position().top,
			dropdownUp = 0-(dropdownHeight-tglHeight-o.dropdownBottom);
			
		$dropdown.css({ top: dropdownUp+"px" });
		$tgl.find("a").click(function(){
			if ($dropdown.attr("rel")=="off") {
				$tglBg = $tgl.css({background:"#ffffff"});
				$(this).attr({rel:"movingOn"});
				$dropdown.animate(
					{ top: tglHeight+"px" },
					500,
					"linear",
					function(){
						$(this).attr({rel:"on"});
						$tgl.find("span.a").toggleClass("open").toggleClass("close");
						$bottomLi.toggleClass("bottom").toggleClass("bottomAct");
					}
				);
			}
			if ($dropdown.attr("rel")=="on") {
				$tglBg = $tgl.css({background:"#FFFFFF url(/^images/header/intensaatmenet.gif) repeat-x scroll left top"});
				$(this).attr({rel:"movingOff"});
				$dropdown.animate(
					{ top: dropdownUp+"px" },
					500,
					"linear",
					function(){
						$(this).attr({rel:"off"});
						$tgl.find("span.a").toggleClass("open").toggleClass("close");
						$bottomLi.toggleClass("bottom").toggleClass("bottomAct");
					}
				);
			}
			this.blur();
			return false;
		});

	}
	
});
