function redirect(a){	
	window.location.href="/galery.php?id="+a;	
}

$(function () {

	// DEFAULT INPUT VALUES
	$("input.text.default").each(function() {
		
		// on focus
		$(this).focus(function () {
			if ( $(this).val() == $(this).attr('title') ) {
				$(this).val('');
			}
		});
		
		// on blur
		$(this).blur(function () {
			if ( $(this).val() == '' ) {
				$(this).val( $(this).attr('title') );
			}
		});
		
		// initialize
		$(this).blur();
	});
	
	
	// ROTATOR AUTOMATIC
	var rotatorTimer;
	
	function rotatorInit() {
		rotatorTimer = window.setInterval(function() {
			// find next
			//console.log()
			var next = $("#rotator ul a.active").eq(0).parent().next().find('a').eq(0);
			//console.log(next);
			if (next.length == 0) {
				next = $("#rotator>ul a").eq(0);
			}			
			//console.log(next);
			//console.log('---------------------------');
			next.click();
		}, 5000);
	};
	
	rotatorInit();
	
	// ROTATOR CLICKS
	$("#rotator ul a").click(function() {
		var a  = $(this);
		var li = a.parent();
		var ul = li.parent();
		var no = ul.children().index(li);
		
		// no clicking on active slides
		if ( a.hasClass('active') ) {
			return false;
		}
		
		// link classes
		ul.find('a').removeClass('active');
		a.addClass('active');
		
		// slides
		//$('#rotator .slide:visible').fadeOut(600);
		$('#rotator div.slide').hide();
		//$('#rotator .slide').eq(no).fadeIn(600);
		$('#rotator .slide').eq(no).show();
		
		// animation
		window.clearInterval(rotatorTimer);
		rotatorInit();
		
		return false;
	});
	
	
	// NEWS ROTATOR AUTOMATIC
	var newsRotatorTimer;
	
	function newsRotatorInit() {
		newsRotatorTimer = window.setInterval(function() {
			// find next
			var next = $("#news-rotator>ul a.active").eq(0).parent().next().find('a').eq(0);
			if (next.length == 0) {
				next = $("#news-rotator>ul a").eq(0);
			}
			next.click();
		}, 5000);
	}
	
	newsRotatorInit();
	
	
	// NEWS ROTATOR CLICKS
	$("#news-rotator>ul a").click(function() {
		var a  = $(this);
		var li = a.parent();
		var ul = li.parent();
		var no = ul.children().index(li);
		
		// no clicking on active slides
		if ( a.hasClass('active') ) {
			return false;
		}
		
		// link classes
		ul.find('a').removeClass('active');
		a.addClass('active');
		
		// slides
		//$('#news-rotator .slide:visible').fadeOut(600);
		$('#news-rotator div.slide').hide();
		$('#news-rotator .slide').eq(no).show();
		
		// animation
		window.clearInterval(newsRotatorTimer);
		newsRotatorInit();
		
		return false;
	});
	
	
	// TAB EQUAL SIZE
	$("#content .tabs").each(function() {
		
		/*var height = 0;
		$(this).find(".tab").each(function() {
			height = Math.max( $(this).height(), height );
		});
		
		$(this).find(".tab").each(function() {
			$(this).height(height);
		});
		*/
		// first tab visible
		$(this).find(".tab").not(':first').hide();
	});
	
	
	// TAB CLICKS
	$("#content .tabs").each(function() {
		var self = this;
		
		$(self).find(">ul li a").click(function() {
			var a  = $(this);
			var li = a.parent();
			var ul = li.parent();
			var no = ul.children().index(li);
			
			// no clicking on active slides
			if ( a.hasClass('active') ) {
				return false;
			}
			
			// link classes
			ul.find('a').removeClass('active');
			a.addClass('active');
			
			// slides
			$(self).find('>.tab:visible').hide();
			$(self).find('>.tab').eq(no).show();
			
			return false;
		});
	});
	
	
	
	// GALLERIES
	$("#content .gallery").each(function() {
		var self = this;
		
		$(this).find('ul a').click(function() {
			var preview = $(self).find('.preview').get(0);
			
			if (preview.tagName == 'IMG') {
				$(preview).attr('src', $(this).attr('href'));
				$(preview).attr('act',$(this).attr('act'));
				//$(preview).bind('click',function(){window.location.href='onet.pl'});
				
				$(preview).bind('click',{id:$(this).attr('act')},function(event){redirect(event.data.id)});
			} else {
				//.. place flash player code below
				$(preview).html( $(this).attr('href') );
			}
			return false;
		});
	});
	
	
	// BOXES EQUAL SIZE
	$("#content .boxes").each(function() {
		$(this).find(".box").addClass('active');
		
		var height = 0;
		$(this).find(".hidable").each(function() {
			height = Math.max( $(this).height(), height );
		});
		
		$(this).find(".hidable").each(function() {
			$(this).height(height);
		});
		
		// first block visible
		$(this).find(".box").not(':first').removeClass('active');
	});
	
	
	// BOXES MOVEMENT
	$("#content .boxes").each(function() {
		var self = this;
		
		$(self).find(".box .link").click(function() {
			var current = $(this).parents().filter(".box");
			var others  = $(self).find(".box").not(current);
			var first   = others.eq(0);
			
			if (current.hasClass('active')) {
				current.removeClass('active');
				first.addClass('active');
			} else {
				current.addClass('active');
				others.removeClass('active');
			}
		});
	});
	
});
