$(document).ready( function() {
	$('.carousel-control a#next').bind('click', function(){
		$('#carousel-content .g318').removeClass('inside');
		var odskok = Math.abs(parseInt($('#carousel-content').css('margin-left')));
		if(odskok == 0) {
			$('#carousel-content').animate({
				'margin-left': '-=672'
			});
			$('#carousel-content .g318').eq(2).addClass('inside');
		} else if(odskok > 0 && odskok < 700) {
			$('#carousel-content').animate({
				'margin-left': '-=672'
			});
			$('#carousel-content .g318').eq(4).addClass('inside');
		} else if(odskok > 700) {
			$('#carousel-content').animate({
				'margin-left': '+=1344'
			});
			$('#carousel-content .g318').eq(0).addClass('inside');
		}
	});
	if ($('#searchphrase').attr('value') == '') {
		$('#searchphrase').attr('value','hledej');
	}
	$('#searchphrase').bind('click', function(){
		if ($(this).attr('value') == 'hledej') {
			$(this).attr('value','');
		}
	});
	$('.carousel-control a#prev').bind('click', function(){
		$('#carousel-content .g318').removeClass('inside');
		var odskok = Math.abs(parseInt($('#carousel-content').css('margin-left')));
		if(odskok == 0) {
			$('#carousel-content').animate({
				'margin-left': '-=1344'
			});
			$('#carousel-content .g318').eq(4).addClass('inside');
		} else if(odskok > 0 && odskok < 700) {
			$('#carousel-content').animate({
				'margin-left': '+=672'
			});
			$('#carousel-content .g318').eq(2).addClass('inside');
		} else if(odskok > 700) {
			$('#carousel-content').animate({
				'margin-left': '+=672'
			});
			$('#carousel-content .g318').eq(0).addClass('inside');
		}
	});
	$('.ears a.ear').bind('click', function(){
		$('.ears a.active').removeClass('active');
		var clicked = $(this);
		$('.my-worn.active').slideUp(400,function(){
			$('.my-worn.active').removeClass('active');
			clicked.addClass('active');
			$('.my-worn').eq($('.ears a.ear').index(clicked)).slideDown();
			$('.my-worn').eq($('.ears a.ear').index(clicked)).addClass('active');
		});
		return false;
	});
	$('#cat_desc .js-show').bind('click', function(){
		$('#cat_desc .js-hide').slideDown();
		$('#cat_desc .js-show').hide();
	});
	$('a.sex').bind('click', function(){
		$('a.sex').removeClass('active');
		$('a.sex').attr('checked',false);
		if($(this).attr('id') == 'sex1j') {
			$('a#sex1j').addClass('active');
			$('#sex1').attr('checked','checked');
		}else{
			$('a#sex2j').addClass('active');
			$('#sex2').attr('checked','checked');
		}
	});

	$('.tooltip').bind('mouseenter', function(event) {
		if($('#tooltip').length < 1) {
			$('body').append('<div id="tooltip"><div class="inner">'+$(this).attr('title')+'</div></div>');
		}
		$('#tooltip').css('z-index','10');
		$('#tooltip').css('position','absolute');
		$('#tooltip').css('left',(event.pageX + 10)+'px');
		$('#tooltip').css('top',(event.pageY - $('#tooltip').height() - 10)+'px');
		$(this).removeAttr('title');
	});
	$(document).bind('mousemove', function(event) {
		if($('#tooltip').length > 0) {
			$('#tooltip').css('left',(event.pageX + 10)+'px');
			$('#tooltip').css('top',(event.pageY - $('#tooltip').height() - 10)+'px');
		}
	});
	$('.tooltip').bind('mouseleave', function() {
		if($('#tooltip').length > 0) {
			$(this).attr('title',$('#tooltip .inner').text());
			$('#tooltip').remove();
		}
	});

});

// onLoad because of webkit
$(window).load( function() {
	$('.bb4r').each(function(){
		var maxheight = 0;
		$(this).children('.bb4').each(function(){
			if($(this).height() > maxheight) {
				maxheight = $(this).height();
			}
		});
		$(this).children('.bb4').css('height',maxheight);
	});
	$('.reklama-container .prouzek').css('top',(508 + $('.bb4r1').height())+'px');
	$('.articles-footer').each(function(){
		var maxheight = 0;
		$(this).children('.article-footer').each(function(){
			if($(this).height() > maxheight) {
				maxheight = $(this).height();
			}
		});
		$(this).children('.article-footer').css('height',maxheight);
	});
	$('a.video').each(function(){
		$(this).html('<img src="/public/mag/play.png" alt="|>" class="play" />' + $(this).html())
	});
});

function summonVideo(elem,address) {
	address = address + '&autoplay=1';
	$(elem).parent().html('<object width="480" height="385"><param name="movie" value="' + address + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + address + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>');
	return false;
}

