﻿var jQueryScriptOutputted = false;
var banerTimer;
function initJQuery() {
    if (typeof (jQuery) == 'undefined') {
        if (!jQueryScriptOutputted) {
            document.write("<scr" + "ipt type=\"text/javascript\" src=\"http://goserbia.com/Scripts/jquery-1.3.2.min.js\"></scr" + "ipt>");
            jQueryScriptOutputted = true;
        }
        setTimeout("initJQuery()", 500);
    } else {
        jQuery(function() {
            jQuery.getScript("http://goserbia.com/Scripts/jsclass.js", function() {
                var obj = new JSONscriptRequest('http://goserbia.com/Baner/Baner');
                obj.buildScriptTag(); 
                obj.addScriptTag();
            }); 
        });
    }
}

var finished = true;
function GS(data) {
    $(".vesti_round").html(data);
    /*$(".strelica_left").bind("click",function(){
        clearInterval(banerTimer);
        Move("left");
        banerTimer = window.setInterval("Move('right')",3000);
    });
    $(".strelica_right").bind("click",function(){
        clearInterval(banerTimer);
        Move("right");
        banerTimer = window.setInterval("Move('right')",3000);
    });*/
    $(".strelica_left").click(function(){
        clearInterval(banerTimer);
        Move("left");
        banerTimer = window.setInterval("Move('right')",3000);
    });
    $(".strelica_right").click(function(){
        clearInterval(banerTimer);
        Move("right");
        banerTimer = window.setInterval("Move('right')",3000);
    });
    
    $(".vest1_round").bind("mouseenter", function(){
        clearInterval(banerTimer);
        $(this).animate({"width": "225px"}, "normal");
    });
    $(".vest1_round").bind("mouseleave", function(){
        if (finished){
            finished = false;
            $(this).animate({"width": "75px"}, "normal",function(){finished=true;});
        }
    });
    $(".vesti_round").bind("mouseleave", function(){
    
        $(".vest1_round").each(function(){
            if (finished)
                if (parseInt($(this).css("width"))==225){
                    finished = false;
                    $(this).animate({"width": "75px"}, "normal",function(){finished=true;});
                }
        });
        banerTimer = window.setInterval("Move('right')",3000);
    });

    banerTimer = window.setInterval("Move('right')",3000);
}

function Move(newPosition)
{
     $(".vest1_round").each(function(){
        if (parseInt($(this).css("width"))==225){
            $(this).css("width","75px");
        }
    });
    if (parseInt($(".vesti_box").css("left")) > 0)
        $(".vesti_box").css("left","-450px");
    if (parseInt($(".vesti_box").css("left")) < -750)
        $(".vesti_box").css("left","-300px");
    if (newPosition == "left"){
        if (parseInt($(".vesti_box").css("left")) == 0)
            $(".vesti_box").css("left","-450px");
         $(".vesti_box").animate({"left": "+=75px"}, "slow");
    }else{
        if (parseInt($(".vesti_box").css("left")) == -750)
            $(".vesti_box").css("left","-300px");
         $(".vesti_box").animate({"left": "-=75px"}, "slow");
    }
    
}

function loadCSS(location) {
    var fileref = document.createElement("link")
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", location)
    document.getElementsByTagName("head")[0].appendChild(fileref);
}
loadCSS("http://goserbia.com/css/banner.css");
var str = [""];
str.push("<div class='banner_round'><div class='pozicija_za_logo'> <a href='http://goserbia.com' target='blank'> <img src='http://goserbia.com/css/images/Baner_logo.png'/></a> </div>");
str.push("<div class='strelica_left'> <a ><img src='http://goserbia.com/css/images/left.png' /></a> </div><div class='vesti_round'>");
str.push("</div><div class='strelica_right'> <a ><img src='http://goserbia.com/css/images/right.png' /></a> </div></div>");
document.write(str.join(''));
initJQuery();