$(document).ready(function(){
	
	var cnt = $('ul.hero').children().size();
	var nextobj, w, h, nw, nh, src, left_st, left_to;
	var left_left = -350;
	var left_cur = 45;
	var left_right = 700;
	var top_cur = 25;
	nh = 340;
	
	// init
	$('.content .buttons .date strong').html('01 / '+cnt);
	$('ul.hero li:first').addClass('selected');

	w = $('ul.hero li.selected .bord-image .image-character img').width();
	h = $('ul.hero li.selected .bord-image .image-character img').height();
	nw = (nh * w) / h;
	nw = Math.round(nw);
	
	if (($.browser.msie)) {
		w = $('ul.hero li.selected .bord-image .image-character img').width();
		h = $('ul.hero li.selected .bord-image .image-character img').height();
		src = $('ul.hero li.selected .bord-image .image-character img').attr('src');
		$('ul.hero li.selected .bord-image .image-character img').css('display', 'none');
		$('ul.hero li.selected .bord-image .image-character').css({width: nw, height: nh});
		$('ul.hero li.selected .bord-image .image-character').css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src+', sizingMethod="scale")');
	} else {
		$('ul.hero li.selected .bord-image .image-character img').css({width: nw, height: nh});
	}
	MyFly(left_st, top_cur, left_cur, top_cur, 0, 1);

	// click
	$('.buttons-area a').click(function(){
		if ($(this).attr('rel') == 'next') {	
			if ($('ul.hero li.selected').is(':last-child')) 
				nextobj = $('ul.hero li:first'); else 
					nextobj = $('ul.hero li.selected').next();
					MyFly(left_cur, top_cur, left_right, top_cur, 1, 0);
					left_st = left_left;
					
		} else {
			if ($('ul.hero li.selected').is(':first-child')) 
				nextobj = $('ul.hero li:last'); else 
					nextobj = $('ul.hero li.selected').prev();
					MyFly(left_cur, top_cur, left_left, top_cur, 1, 0);
					left_st = left_right;
		}
		setTimeout(function(){
			$('ul.hero li.selected').removeClass('selected');
			nextobj.addClass('selected');
			$('.content .buttons .date strong').html($('ul.hero li.selected').attr('title')+' / '+cnt);
			
			w = $('ul.hero li.selected .bord-image .image-character img').width();
			h = $('ul.hero li.selected .bord-image .image-character img').height();
			nw = (nh * w) / h;
			nw = Math.round(nw);
			
			if ($.browser.msie) {
				src = $('ul.hero li.selected .bord-image .image-character img').attr('src');
				$('ul.hero li.selected .bord-image .image-character img').css('display', 'none');
				$('ul.hero li.selected .bord-image .image-character').css({width: nw, height: nh});
				$('ul.hero li.selected .bord-image .image-character').css('filter', 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src='+src+', sizingMethod="scale")');
			} else {
				$('ul.hero li.selected .bord-image .image-character img').css({width: nw, height: nh});
			}
			
			MyFly(left_st, top_cur, left_cur, top_cur, 0, 1); 
				
		}, 600);	
	
	});
	
	function MyFly( left_b, top_b, left_to, top_to, op_b, op_to){
		$('ul.hero li.selected div.bord-image').css({left: left_b, top: top_b, opacity: op_b});
		$('ul.hero li.selected div.bord-image').animate({ 
				left: left_to,
				top: top_to,
				opacity: op_to
			}, 600);
	}
	
	//lays 
	var tm = 600;
	function runLay(){
		$('.lay').fadeIn(tm, function(){
			$('.lay').fadeOut(tm, function(){
				runLay2();
			});
		});
	}
	function runLay2(){
		$('.lay').fadeIn(tm, function(){
			$('.lay').fadeOut(tm, function(){
				runLay();
			});
		});
	}
	
	if ($('body').hasClass('home')) {
		runLay();
	}
});


