var player = false;
$(document).ready(function(){
		if ($("a.popin-img[rel='gal']").size() > 0) {
			$("a.popin-img[rel='gal']").overlay({
				target: '#gallery',
				expose: "#111"
			}).gallery({
				disabledClass: 'inactive',

				template: '<strong>${title}</strong> <span>(${index} / ${total})</span>'
			}); 
		}
		
		if ($(".scrollable").size() > 0) {
			$(".scrollable").scrollable({
				size: 4, clickable: false
			});
			$("a.a-img").click(function() {
				$("img#imgVier").attr("src", $(this).attr("href"));
				$("img#imgVier").parent('a').attr('href', $(this).attr("rel"))
				return false;
			});
		}
		
		$("#images-tab").click(function() {
			$("#images-tab-inner").show();
			$("#images-tab").addClass("active-tab");
			$("#images-tab").removeClass("inactive-tab");
			$("#video-tab-inner").hide();
			$("#video-tab").addClass("inactive-tab");
			$("#video-tab").removeClass("active-tab");
		});
		
		$("#video-tab").click(function() {
			$("#images-tab-inner").hide();
			$("#images-tab").addClass("inactive-tab");
			$("#images-tab").removeClass("active-tab");
			$("#video-tab-inner").show();
			$("#video-tab").addClass("active-tab");
			$("#video-tab").removeClass("inactive-tab");
		});
		
		$(".a-movie").click(function() {
			player.sendEvent('load', $(this).attr('rel'));
			return false;
		});
		
	/*	$(".menu-item").mouseover(function() {
			$(".div_submenu1").hide();
			$("#s" + $(this).attr('id')).show();
		});*/
		
		
		// banners
		var bnrTs = [], curT = 0, d = 1, jbIn, cP = tP = 0;
		if ($(".bnr_item").size() > 1) {
			t = 0;
			$.each($(".bnr_item"), function(i, v) {
				bnrTs[i] = t;
				t -= $(v).height();
			});
//			bnrTs.pop();
			jbIn = $(".bnr_inner");
			setInterval(chngB, 10000);
			setInterval(animBScroll, 50);
		}
		
		function chngB() {
			curT += d;
			tP = bnrTs[curT];
			if ((curT + d >= bnrTs.length) || (curT + d < 0)) {
				d = -d;
			}
//			alert(cP);
		}
		
		function animBScroll() {
			dy = 20;
			if (tP - cP < 0) {
				cP -= dy;
			} else if (tP - cP > 0) {
				cP += dy;
			}
			if (Math.abs(tP - cP) <= dy) {
				cP = tP;
			}
			jbIn.css('top', cP + 'px');			
		}
		
		// bron-form		
		$('.custom-checkbox').click(function(){
			$(this).toggleClass('checked');
			$(this).find('input').attr(
				'value',
				$(this).hasClass('checked') ? '1' : '0'
			);
		});
		
		$('.custom-select').click(function(){
			$(this).attr('rel', 'nohide');
			$('.custom-select[rel!=nohide] .variants').hide();
			$(this).attr('rel', '');
			$(this).find('.variants').toggle();
			return false;
		});
		
		$('body').click(function(){
			$('.custom-select .variants').hide();
		});
		
		$('.custom-select .variants div').click(function(){
			cs = $(this).parents('.custom-select');
			cs.find('.variants div').removeClass('current-variant');
			$(this).addClass('current-variant');
			val = $(this).html().replace(/^\s\s*/, '').replace(/\s\s*$/, '');
			cs.find('.current').html(val);
			cs.find('input').attr('value', val);
		});
		
		
});

function playerReadyCallback(obj) {
	player = document.getElementById(obj['id']);
};
