$(function(){
	$('.controlers a').each(function(i,el){
		$(el).click(function(){
			changeOnClick(el);
			$('.video_container').animate({left : -(261*i)}, 400);
		});
	});

	function changeOnClick(elm){
		var active = $('#active_btn');
		if(active){
			active.removeAttr('id');
		}
		$(elm).attr("id","active_btn");
	}
/*******Light Box******/
	$('a[rel="LightBox"]').click(function(){
		$('<div id="overlay" style="height:'+document.body.offsetHeight+';"></div>'+
			'<div id="lightbox">'+
				'<div id="outerContainer">'+
						'<a href="javascript:" id="btnClose" title="close"><img src="public/images/close.png" alt="Close" /></a>'+
						'<div id="lightboxContainer">'+
						'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"'+
							'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"'+
							'width="435"'+
							'height="320"'+
							'align="middle"'+
							'id="main">'+
						'<param name="allowScriptAccess" value="sameDomain" />'+
						'<param name="movie" value="public/flash/fino_flash_player.swf" />'+
						'<param name="allowFullScreen" value="true" />'+
						'<param name="quality" value="high" />'+
						'<param name="bgcolor" value="#ffffff" />'+
						'<param name="FlashVars" value="movieUrl='+$(this).attr('href')+'" />'+
						'<embed src="public/flash/fino_flash_player.swf"'+
							   'width="435"'+
							   'height="320"'+
							   'autostart="false"'+
							   'quality="high"'+
							   'bgcolor="#ffffff"'+
							   'FlashVars="movieUrl='+$(this).attr('href')+'"'+
							   'name="main"'+
							   'align="middle"'+
							   'allowFullScreen="true"'+
							   'allowScriptAccess="sameDomain"'+
							   'type="application/x-shockwave-flash"'+
							   'pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
					'</object>'+
					'</div>'+
				'</div>'+
			'</div>').appendTo($('div#page'));

		$('#btnClose').click(function(){
			$('#lightbox').remove();
			$('#overlay').remove();
		});
		return false;
	});
/*******end Light Box******/

/******* Carousel *******/
function Carousel(root,items,next,prev,paragraf){
	var speed = 3000;
	var run = setInterval('rotate()', speed);
	var run2 = setInterval('rotate2()', speed);
	var item_width = $(items).width()+4;
	var left_value = item_width * (-1);

	$(items+':first').before($(items+':last'));
	$(root).css({'left' : left_value+4});

	$(prev).click(function() {
		var left_indent = parseInt($(root).css('left')) + item_width;
		$(paragraf).fadeOut(200, function(){
			$(this).text($(items+':nth-child(1)').attr('alt'));
		});
		$(root+':not(:animated)').animate({'left' : left_indent}, 600,function(){
			$(paragraf).fadeIn();
			$(items+':first').before($(items+':last'));
			$(root).css({'left' : left_value});
		});
		return false;
	});

	$(next).click(function() {
		var left_indent = parseInt($(root).css('left')) - item_width;
		$(paragraf).fadeOut(200, function(){
			//$(this).text($(items+':nth-child(3)').attr('alt'));
            $(this).text($(items).eq(2).attr('alt'));

		});
		$(root+':not(:animated)').animate({'left' : left_indent}, 600, function () {
            $(paragraf).fadeIn();
			$(items+':last').after($(items+':first'));

			$(root).css({'left' : left_value});
		});
		return false;
	});
}

Carousel('#carouser-hit-images','#carouser-hit-images img','#hit_next','#hit_prev','.carousel-hit p');
Carousel('#carouser-new-images','#carouser-new-images img','#new_next','#new_prev','.carousel-new p');

/*******end Carousel *******/
});
function rotate() {
	$('#hit_next').trigger('click');
}
function rotate2() {
	$('#new_next').trigger('click');
}
