var groupItems = null;
var mov        = false;
var dur        = false;

function goLenta(){
    var parentObj  = $('#slideshow');
    groupItems = $(parentObj).find(".items");
    return anim(parseInt(groupItems.css("marginLeft")));
}

function anim(marginLeft) {		if(!mov) mov = groupItems.find('img:first').outerWidth(true);
		if(!dur) dur = mov*24;
        marginLeft = marginLeft-mov+"px";
        groupItems.animate({"marginLeft": marginLeft},dur,"linear",function(){
                var width = groupItems.find('img:first').outerWidth(true);
                $(groupItems.find('img:first')).appendTo(groupItems);
    			groupItems.css("marginLeft",parseInt(marginLeft)+width+"px");
    			mov = dur = false;
                return anim(parseInt(marginLeft)+width);
    	});
}
function noanim(){
    groupItems.stop();
}

$(document).ready(function(){

    $('#slideshow2').mouseover(function(e){
		//$('.big_foto_wrap').css('left',e.pageX+10+'px');
		//PosBlockBigPhoto(e);
		//ZindexFlag(e);
		//$('#slideshow .scrollable').css('z-index',10000);
		//$('#ribbons_over').fadeOut('slow');
	});

	$('#slideshow2').mouseout(function(e){
		//$('#slideshow .scrollable').css('z-index',10);
		//$('#ribbons_over').fadeIn('slow');
	});

	$('#slideshow2 .items').mousemove(function(e){
		//$('.big_foto_wrap').css('left',e.pageX+10+'px');
		//PosBlockBigPhoto(e);
	});

	/*$('.items').mousemove(function (event) {
	        event.stopPropagation();
	});*/

});// ready

var CHANGE_Z_FLAG = false;

/*function ZindexFlag(e)
{	var x = e.pageX;
	var flagBlock = $('#ribbons_over');
	var minLeft = parseInt(flagBlock.css('left'))-250;
	var maxLeft = minLeft+466+250;
	if(x > minLeft && x < maxLeft){    	CHANGE_Z_FLAG = true;	}
	//alert(x +' > '+ minLeft +' && '+ x+' < '+maxLeft);}*/

function PosBlockBigPhoto(e)
{    var docW = $(document).width();
    var x = e.pageX;
    var docW2 = docW/2;
    if(x <= docW2){
		$('.big_foto_wrap').css('left',x+10+'px');
        $('.big_foto_shadow').css({'float':'left'});
	}else{
		var right = docW-x;
		$('.big_foto_wrap').css({'right':right+10+'px'});
        $('.big_foto_shadow').css({'float':'right'});
	}}

function showTopImg(e,obj,img)
{
	obj = $('#'+obj);

	var width = obj.width();
	var width_big = width/152*204;
	var marginleft = (width_big-width)/2;

	//var x = e.pageX;
	var x = e.clientX;
	var flagBlock = $('#ribbons_over');
	//var offset = flagBlock.offset();
	//var minLeft = offset.left-width_big-80;
	var minLeft = parseInt(flagBlock.css('left'))-width_big-80+marginleft;
	//var maxLeft = minLeft+466+width_big+160-marginleft;
	var maxLeft = parseInt(flagBlock.css('left'))+466+width_big-160-marginleft;
	if(x > minLeft && x < maxLeft){
    	CHANGE_Z_FLAG = true;
	}

	if(CHANGE_Z_FLAG){
		$('#slideshow .scrollable').css('z-index',10000);
	}


	obj.animate({		marginTop: "-25px",
		marginLeft: "-"+ marginleft +"px",
        height: "204px",
        borderWidth: "3px"
 		}, 'fast', function(){ 			obj.attr('src','/pics/gallery/'+img);
 	});}

function hideTopImg(obj,img)
{
	obj = $('#'+obj);

	if(CHANGE_Z_FLAG){
		$('#slideshow .scrollable').css('z-index',10);
		CHANGE_Z_FLAG = false;
	}

	obj.animate({		marginTop: 0,
		marginLeft: 0,
        height: "152px",
        borderWidth: "0px"
 		}, 'fast', function(){
 			obj.attr('src','/pics/gallery/'+img);
 	});}

