<!--

var locActive = 1;

$(document).ready(function() {
    
    $('.lokali_item').bind('click', function() {
        var sp = $(this).attr('id').split("_");
        moveDot( sp[1]);
    });
	
    //	$('.lokali_mapa_btn').bind('click', function() {
    //		var newLoc = locActive;
    //		 if ($(this).attr('id') == "btn_left") {
    //			 newLoc--;
    //		 }
    //		 else {
    //			 newLoc++
    //		 }
    //		
    //		 if (newLoc < 1)
    //			 newLoc = 8;
    //		 else if (newLoc > 8)
    //			 newLoc = 1;
    //		 
    //		  moveDot( newLoc);
    //		});

    $('.lokali_item').click(function() { 
        var idful = $(this).attr('id').split("_"); 
	    
        var id = idful[1];
        //alert(url);
        moveDot(id, true);
	    
        return false; 
    });
	
    $('area').click(function() { 
        var id = $(this).attr('alt'); 
	    
        //alert(url);
        moveDot(id, true);
	    
        return false; 
    });

	
    $("input[type=file]").filestyle({ 
        image: base_url + "img/file_upload.jpg",
        imageheight : 98,
        imagewidth : 84,
        width : 50
    });
	
    if (!$.browser.opera) {

        $('select.select').each(function(){
            var title = $(this).attr('title');
            if( $('option:selected', this).val() != ''  ) title = $('option:selected',this).text();
            $(this)
            .css({
                'z-index':10,
                'opacity':0,
                '-khtml-appearance':'none'
            })
            .after('<span class="select">' + title + '</span>')
            .change(function(){                
                val = $('option:selected',this).text();               
                $(this).next().text(val);
                $('#pozicija').val(val);
                //alert(val);
                
            })
        });

    };
	 
});

function moveDot(id, show){

    // alert(sp[1]);
    // $('.dot').attr('id', 'dot_' + id);
	
	
    $('#lokali_' + locActive).removeClass('active');	
    $('#kontakt_' + locActive).hide();
	
    locActive = id;
    $('#lokali_' + locActive).addClass('active');
    $('#kontakt_' + locActive).show();
	
    if (show == true)
        getImgGallery(id);
}

function getImgGallery(id){
    var _url = base_url + 'lokali/ajax2/' + id;
    var _hld = 'lokali_mapa_img';
	
    $('#' + _hld).css('background-color', 'white');
    $('#' + _hld).html('<br ><br /><br /><br ><img src="'+ base_url + 'img/loading25.gif" alt="loading" />' );
	
    $.ajax({
        url: _url,
        dataType: 'json',
        success: function(data){
            // alert('data');
            $('#' + _hld).html(data['content']);
            //btn_left
            $('#btn_left').unbind();
            $('#btn_right').unbind();
            $('#btn_left').click(function(){
                slider2(-1,data['count']);
            });				
            $('#btn_right').click(function(){
                slider2(1,data['count']);
            });
            $('#btn_left').css('background-position','-0px 0px');
            $('#btn_right').css('background-position','-28px 0px');
                                
            pos = 1;
            $('#' + _hld).css('background-color', 'transparent');
        },
        error: function(xhr){
            alert(xhr.readyState + '\n' + xhr.status + '\n' + xhr.statusText);
        }
    });
}

var inAnim=false;
var pos = 0;
function slider2(gde, uk) {

    if (inAnim)
        return;

    var showhld = 0;
    var hidehld = 0;

    hidehld = pos;
    showhld = pos + gde;

    if(showhld == 0 || showhld > uk)
        return;

    pos = showhld;

    
    
    //$("#imghld_" + hidehld).hide();
    //$("#hld_" + showhld).fadeIn(1500);
    //$("#hld_" + hidehld).fadeOut(1000, fout("#hld_" + showhld));
    //$("#hld_" + hidehld).fadeOut(1000);
    //$("#hld_" + showhld).delay(1000).fadeIn(1500);
    inAnim = true;
    $("#imghld_" + hidehld).fadeOut(500, function () {
        $("#imghld_" + showhld).fadeIn(200, function () {
            inAnim = false;
        });
    });


}

function slider(gde,koliko) {
    if(triInAnim)
        return;
	
    var pomeri = 807;
    var hld = 'gallery';
    var left= $("#" + hld).css("left");
    left = parseInt(left.replace("px",""));
    left=-left;
	
    if(gde == 1) {
        if(left == (koliko-1)*pomeri) {
            gde = -1;
            pomeri = left;
        }
    }
    else {
        if( left == 0) {
            gde = 1;
            pomeri = (koliko-1)*pomeri;
        }
    }
	
    triInAnim=true;
    if(gde == 1) {
        $("#" + hld).animate(
        {
            "left":"-="+pomeri+"px"
            },
        500,
        function() {
            triInAnim=false;
        });
    }
    else {
        $("#" + hld).animate(
        {
            "left":"+="+pomeri+"px"
            },
        500,
        function() {
            triInAnim=false;
        });
    }
}
	
var tri_slajder_rot_over=false;
var tri_slajder_rot_koliko=0;
function tri_slajder_rot(gde,koliko) {
    tri_slajder_rot_koliko = koliko;
    if(!tri_slajder_rot_over)
        tri_slajder(gde,koliko);
	
    setTimeout('tri_slajder_rot('+gde+', '+koliko+')',6000);
}


// -->

