$(document).ready(function()	{ /* All scripts begin */

	var page = 0;

	$('#left a img').mouseover(function(){
		if ( $(this).attr('class') != "active" )	{
			$(this).attr({ src: "/templates/images/left-"+$(this).attr('alt')+"_on.png" });
		}
	});
	$('#left a img').mouseout(function(){
		if ( $(this).attr('class') != "active" )	{
			$(this).attr({ src: "/templates/images/left-"+$(this).attr('alt')+".png" });
		}
	});

	$('.intleft img').mouseover(function(){
		$(this).attr({ src: "/templates/images/ico-arrowleftba.png" });
	});
	$('.intleft img').mouseout(function(){
		$(this).attr({ src: "/templates/images/ico-arrowleftb.png" });
	});
	$('.intright img').mouseover(function(){
		$(this).attr({ src: "/templates/images/ico-arrowrightba.png" });
	});
	$('.intright img').mouseout(function(){
		$(this).attr({ src: "/templates/images/ico-arrowrightb.png" });
	});

	if (page == 0)	{
		$('.intleft img').hide();
	}

	$('.intleft img').click(function()	{
		$('.intright img').show();
		page_up = page - 1;	/* countdown pages */
		if (page_up >= 0)	{	/* until $page_up is bigger or equal to 0 */
			$('#intpage_'+page).hide();	/* hide active page */
			$('#intpage_'+page_up).show();	/* show previous page */
			page = page - 1;	/* decrase $page */
			page_temp = page - 1;
			if (page_up <= 0)	{
				$(this).hide();
			}
		}
	});
	$('.intright img').click(function()	{
		$('.intleft img').show();
		page_down = page + 1;
		if (page_down <= intpages)	{
			$('#intpage_'+page).hide();
			$('#intpage_'+page_down).show();
			page = page + 1;
			page_temp = page + 1;
			if (page_down == intpages)	{
				$(this).hide();
			}
		}
	});

	$('a.buy-mp3').click(function()	{
		$('#box-content').load( '/scripts/sms-mp3.php?track=' + $(this).attr('name') );
		$('#box-product').show();
	});

	$('a.continue').click(function()	{
		$('#box-product').hide();
	});

	/*
		Gallery script
	*/
	$('ul.gallery').galleria({
		history   : true, // activates the history object for bookmarking, back-button etc.
		clickNext : true, // helper for making the image clickable
		insert    : '#gallery_mainimg', // the containing selector for our main image
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes

			// fade in the image & caption
			image.css('display','none').fadeIn(1000);
			caption.css('display','none').fadeIn(1000);

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);

			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');

			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here

			// fetch the thumbnail container
			var _li = thumb.parents('li');

			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';

			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);

			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});

	/*
		Buy script
	*/
	$(".buy a").click(function()	{
		reg = $(this).attr("rel");
		if ( reg == 'reg' )
		{
			$('#regwindow').show();
		}
	});

	$('#regwindow a.continue').click(function(){
		$('#regwindow').hide();
	});

	$('#regwindows a.continue').click(function(){
		$('#regwindows').hide();
	});

	$('a.registrace').mouseover(function(){
		$('a.registrace img').attr({ src: "/templates/images/ico-reg_hover.png" });
	});

	$('a.registrace').mouseout(function(){
		$('a.registrace img').attr({ src: "/templates/images/ico-reg.png" });
	});

	$("a.guest").click(function()	{
		link = $(this).attr("rel");
		$('#regplay').show();
		$('#regplay a.continue').attr({ href: link });
		return false;
	});

	var playerwindow;
	function player_window(url)
	{
		playerwindow = window.open(url,'player','height=320,width=430');
		if (window.focus)
		{
			playerwindow.focus();
		}
	}

	$("#open_player a").click(function() {
		var sample = '/player.php?id='+$(this).attr('rel');
		player_window(sample);
		return false;
	});

	$("a.switch_cz").click(function()	{
		$('.mp3_price').html("40,00 Kč");
		$('.ring_price').html("40,00 Kč");
	});

	$("a.switch_sk").click(function()	{
		$('.mp3_price').html("1,60 € / 48,00 SK");
		$('.ring_price').html("1,60 € / 48,00 SK");
	});

	$('a.switch_sk img').mouseover(function(){
		$(this).attr({ src: "/templates/images/flag-sk_on.gif" });
	});
	$('a.switch_sk img').mouseout(function(){
		$(this).attr({ src: "/templates/images/flag-sk.gif" });
	});

	$('a.switch_cz img').mouseover(function(){
		$(this).attr({ src: "/templates/images/flag-cz_on.gif" });
	});
	$('a.switch_cz img').mouseout(function(){
		$(this).attr({ src: "/templates/images/flag-cz.gif" });
	});

	/*
		Buy album
	*/
	$('.buy-album a').click(function(){
		kn = $(this).attr('rel');
		$('#box-cart').show();
		$('#box-cart .box-content').html('<div style="text-align: center"><img src="/templates/images/loading.gif"/></div>');
		$('#box-cart .box-content').load('/scripts/cart.php?a=add&q='+kn);
	});

	$('#box-cart .continue').click(function(){
		$('#box-cart').hide();
	});

	/*
		Buy ringtone
	*/
	$('a.buy-ring').click(function(){
		track = $(this).attr('name');
		$('#box-ats').show();
		$('#box-ats .box-content').load('/scripts/ats.php?a=ring&t='+track);
	});
	$('a.buy-mp3').click(function(){
		track = $(this).attr('name');
		$('#box-ats').show();
		$('#box-ats .box-content').load('/scripts/ats.php?a=track&t='+track);
	});
	
	$('a.buy-real-discount').click(function(){
		track = $(this).attr('name');
		alert('pokus');
		$('#box-ats').show();
		$('#box-ats .box-content').load('/scripts/ats.php?a=ring&t='+track);
	});
	
	$('a.buy-fulltrack-discount').click(function(){
		track = $(this).attr('name');
		alert('pokus');
		$('#box-ats').show();
		$('#box-ats .box-content').load('/scripts/ats.php?a=track&t='+track);
	});
	
	
	$('#box-ats a.continue').click(function(){
		$('#box-ats').hide();
	});

}); /* All scripts end */