
var rotator = null;

jQuery(document).ready(function($){
	
	var slider = $('#slider');
	var itemsHolder = slider.find('ul');
	var items = slider.find('li');
	var loader = $('#slider-holder').find('.loader');
	
	var anchors = slider.find('a');
	var nHeight = anchors.first().innerHeight();
	anchors.each(function(){
		if($(this).innerHeight() > nHeight)nHeight = $(this).innerHeight();	
	});
	
	
	var fullHeight = nHeight + 20;
	anchors.height(nHeight);
	items.height(fullHeight);
	slider.height(fullHeight);
	loader.css({
		height: fullHeight,
		opacity: '0.7'	
	});
	
	
	
	slider
		.find('img')
		.WaitForImgLoad({
			onload: function(){
			
				loader.animate({opacity:0},350,'easeOutQuad',function(){
				
					$(this).remove();
					
					//-- START SLIDER
						if(slider.find('li').length > 4)
						{
							rotator = slider.Slider({
								duration: 1100,
								interval: 10000,
								effect: 'easeInOutExpo',
								panelsNum: 4,
								orientation: 'horizontal',
								continuous: true,
								playOrder: 'ascending',
								holderQuery: 'ul',
								panelsQuery: 'li',
								hasPrevNext: true,
								prevQuery: '.previous',
								nextQuery: '.next'
							});	
							slider.parent().find('.next,.previous').css('display','block');	
						}
					//-- END SLIDER
					
					//-- START ANCHOR HOVER
					
						var anchorMinHeight = nHeight;
						var anchorMaxHeight = nHeight + 20;
						
						var duration = 250;
						var effectOut = 'easeOutQuad';
						var effectIn = 'easeInQuad';
						
						anchors.hover(
							function($e){
								var anchor = $(this);
								var img = anchor.find('img');
								var title = anchor.find('span');
								
								anchor
									.animate({
										width: 228,
										height: anchorMaxHeight,
										top: 0,
										left: 0	
									},duration,effectOut);	
									
								img.animate({width:228,height:188},duration,effectOut);
								
								title.animate({
									'padding-top': '20px',
									'padding-bottom': '20px',
									'padding-left': '15px',
									'padding-right': '15px'
								},duration,effectOut);
							},
							function($e){
								var anchor = $(this);
								var img = anchor.find('img');
								var title = anchor.find('span');
								
								anchor
									.animate({
										width: 208,
										height: anchorMinHeight,
										top: 10,
										left: 10	
									},duration,effectIn);	
								
								img.animate({width:208,height:172},duration,effectIn);
								
								title.animate({
									'padding-top': '15px',
									'padding-bottom': '15px',
									'padding-left': '10px',
									'padding-right': '10px'
								},duration,effectIn);	
								
							}
						);
						
					//-- END ANCHOR HOVER
				});	
			}
		});
	
	
	
	
	
	
	
	
		
	
	
});
