$(document).ready(function(){
 var new_map='<span class="map"><span class="s1" /><span class="s2" /><span class="s3" /><span class="s4" /><span class="s5" /><span class="s6" /><span class="s7" /><span class="s8" /><span class="s9" /></span>';
 var new_bg=$("<span>");
 new_bg.addClass("bg");
 $("#polska li a").append(new_map);
 $("#polska li a").append(new_bg); 
 
 	var cfg = ($.hoverintent = {
		sensitivity: 7,
		interval: 100
	});
		
	$.event.special.hoverintent = {
		setup: function() {
			$(this).bind("mouseover", jQuery.event.special.hoverintent.handler);
		},
		teardown: function() {
			$(this).unbind("mouseover", jQuery.event.special.hoverintent.handler);
		},
		handler: function(event) {
			event.type = "hoverintent";
			var self = this,
				args = arguments,
				target = $(event.target),
				cX, cY, pX, pY;
				
			function track(event) {
				cX = event.pageX;
				cY = event.pageY;
			};
			pX = event.pageX;
			pY = event.pageY;
			function clear() {
				target.unbind("mousemove", track).unbind("mouseout", arguments.callee);
				clearTimeout(timeout);
			}
			function handler() {
				if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
					clear();
					jQuery.event.handle.apply(self, args);
				} else {
					pX = cX; pY = cY;
					timeout = setTimeout(handler, cfg.interval);
				}
			}
			var timeout = setTimeout(handler, cfg.interval);
			target.mousemove(track).mouseout(clear);
			return true;
		}
	};

 				// Accordion
				$("#accordion").accordion({ header: "h3", event: "click hoverintent", autoHeight: false });

	
			$("a.zoom").fancybox({
				'titlePosition'  : 'over',
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			
			$("#mail").fancybox({
				'width'				: 640,
				'height'			: 480,
				'autoDimensions'	: false,
				'autoScale'			: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'fade',
				'overlayShow'		: false,
				'titleShow'			: false,
				'type'				: 'iframe'
			});
			
			$("#opinionBrowse").fancybox({
				'width'				: 640,
				'height'			: 480,
				'autoDimensions'	: false,
				'autoScale'			: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'fade',
				'overlayShow'		: false,
				'titleShow'			: false,
				'type'				: 'iframe'
			});
			
			$("#opinionAdd").fancybox({
				'width'				: 640,
				'height'			: 480,
				'autoDimensions'	: false,
				'autoScale'			: true,
				'transitionIn'		: 'elastic',
				'transitionOut'		: 'fade',
				'overlayShow'		: false,
				'titleShow'			: false,
				'type'				: 'iframe'
			});

//$("form.jqtransform").jqTransform();

//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});
	
});
/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */ 
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

this.tooltip_span = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("span.getMONTH").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip_span'>"+ this.t +"</p>");
		$("#tooltip_span")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("slow");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip_span").remove();
    });	
	$("span.getMONTH").mousemove(function(e){
		$("#tooltip_span")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

function divShowBox(){
	$("div#disabilitybox").show();
	$("div#profilbox").show();
}

function divHideBox(){
	$("div#disabilitybox").hide();
	$("div#profilbox").hide();
}

// starting the script on page load
$(document).ready(function(){
	tooltip();
	tooltip_span();
});

$(document).ready(function() {
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
});
