// JavaScript Document
$(document).ready(function()
{
	/**
	 * put aside box lower
	 */
	article_header_height = $('article header').height();
	$('aside').css({top: (article_header_height + 50) + 'px'});
	
	/**
	 * hover effect for aside boxes
	 */	
	$('aside section .box img').each(function() {
		
		var imageurl = $(this).attr("src");
		//console.log(imageurl);
		var imageheight = $(this).attr("height");
		
		$(this).css({
			background: 'url(' + imageurl + ') no-repeat',
			height: imageheight + 'px'
		}).attr('src', '/website/static/source/img/spacer.gif');
		
		$(this).mouseenter(function(){
			$(this).css({
				background: 'url(' + imageurl + ') no-repeat -' + $('aside section .box img').attr("width") + 'px 0px'
			});
		}).mouseleave(function(){
			$(this).css({
				background: 'url(' + imageurl + ') no-repeat 0px 0px'
			});
		});		

	});
	
	/**
	 * image popup
	 */	
	$("a.openImage").fancybox({
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});

	/**
	 * registration form
	 * behaviour for dealer stand selection
	 */
	if(!$('#dealer').attr('checked'))
	{
		$(".dealer").each(function() {
			$(this).css({'display':'none'});	
		});
	}
	$("#dealer").click(function() {
		var display = 'none';
		$('#DEALER_SELECTION').remove();
		if($(this).attr('checked')) var display = 'block';
		
		$(".dealer").each(function() {
			$(this).css({'display':display});	
		});
	});
	$(".dealer dd label").click(function(e) {
		
		$(".dealer dd label").each(function() {
			$(this).children('input').attr('checked',false);
		});
		$(this).children('input').attr('checked',true);
	});

	/**
	 * z-index for review gallery
	 */	
	$(".gallerybox").each(function(){
		
		$(this).children('.top').css({
			'z-index': 1,
			'top': getRandom(-15, -5)+'px',
			'background': 'url(/website/static/source/img/masktop' + getRandom(1, 3) + '.png)',			
			'background-repeat': 'no-repeat'			
		});
		$(this).children('.bot').css({
			'z-index': 2,
			'bottom': getRandom(-15, -5)+'px',
			'background': 'url(/website/static/source/img/maskbot' + getRandom(1, 3) + '.png)',			
			'background-repeat': 'no-repeat'
		});
	});
	
	/**
	 * hover effect for review gallery
	 */	
	$(".gallerybox").each(function(){
		$(this).data("t",$("div:eq(0)",this).css("top"));
		$(this).data("b",$("div:eq(1)",this).css("bottom"));
		$(this).hover(
			function(){
				$("div:eq(0)",this).animate({"top":"-30px"},200);	
				$("div:eq(1)",this).animate({"bottom":"-30px"},200);	
			},
			function(){
				$("div:eq(0)",this).stop().animate({"top":$(this).data("t")},300);	
				$("div:eq(1)",this).stop().animate({"bottom":$(this).data("b")},300);
			}
		);
	});
	
	/**
	 * artist list
	 * split line position
	 */	
	$("article section #artistList .artists").each(function(){
		$(this).css({
			'height': $(this).height()+'px',
			'background-position': 'center ' + $(this).height()+'px'
		});
	});	
	

});

/**
 * z-index for review gallery
 */
function getRandom( min, max ) {
	
	if( min > max ) return( -1 );

	if( min == max ) return( min );
 
    return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}
