/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
var blinking_on_i;
var temp_image;

function place_regions(zero) {
    var time = 0;
    if(typeof(zero) != 'undefined') {
        time = zero;
    }
    setTimeout(function() {
        var $top =  $(window).scrollTop();
        var $height = $(window).height();
        $('#logo').animate({top: $top}, time);
        $('#logo_lace').animate({top: $top}, time);
        $('#right-bar').animate({top: ($top + 50)}, time);
        $('#botton_b').animate({top: ($top + $height - 109)}, time);

        $('#logo_lace').height($(window).height());        
    }, 50)
    
}

$(document).ready(function() {
    $('#logo_lace').height($(window).height());
    if( navigator.userAgent.match(/Android/i) ||
        navigator.userAgent.match(/webOS/i) ||
        navigator.userAgent.match(/iPhone/i) ||
        navigator.userAgent.match(/iPod/i) 
      ) {
        $('#logo, #logo_lace, #right-bar, #botton_b').css('position', 'absolute');
        place_regions();
        $(window).scroll(function() {
            place_regions(200);
        })        
      }
      else 
        $('#logo, #logo_lace, #right-bar, #botton_b').css('position', 'fixed');

    
    if($('#banner').length>0 && typeof(banner) != 'undefined') {
        $('#banner').append('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+banner.width+'" height="'+banner.height+'" align="middle"><param name="allowScriptAccess" value="sameDomain" /><PARAM NAME=wmode VALUE="transparent"><param name="movie" value="'+banner.src+'?link=' + banner.link + '" /><param name="quality" value="high" /><param name="bgcolor" value="#f90204" /><embed src="'+banner.src+'?link=' + banner.link + '" WMODE="transparent" quality="high" bgcolor="#f90204" width="'+banner.width+'" height="'+banner.height+'" name="vesna" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>')
    }

        //menu text hover event
        $('.menu li').each(function(i) {
            var classes = $(this).attr('class');
            var id = classes.replace(/(_.{2,})/, '');
            $(this).hover(
            function() {                 
                    if(navigator.appVersion.indexOf('MSIE') != -1) {
                        $('#'+id).show()
                    }
                    else {
                        //blinking_on($(this).children('a'));
						$(this).children('a').animate({opacity: 0.6}, 100);
                        $('#'+id).fadeIn(100);
                    }
                },
                function() {
                    if(navigator.appVersion.indexOf('MSIE') != -1) {
                        $('#'+id).hide()
                    }
                    else {
                        /*clearInterval(blinking_on_i)
                        obj = $(this).children('a');
                        setTimeout(blinking_off,400,obj)*/
						$(this).children('a').animate({opacity: 1}, 100);
                        $('#'+id).fadeOut(100);
                    }
                }
            )
        })

    //menu with pics (inseting and placing div's in li's)
    $('.menu-pics li').each(function() {
        var classes = $(this).attr('class');
        var id = classes.replace(/(_.{2,})/, '');
        $(this).append($('#'+id));

        var w = {}
        w.pic = $('#'+id).width()
        w.text = $(this).children('a').width()
        w.li_pl = parseInt($(this).css('padding-left').replace(/px/,''))
        w.li_pr = parseInt($(this).css('padding-right').replace(/px/,''))
        
        w.diff = Math.round((w.pic-w.text)/2)
        if(w.li_pl==0)
            $('#'+id).css('left',w.diff*(-1));
        else if(w.li_pr==0)
            $('#'+id).css('right',w.diff*(-1));
        else {
            w.diff = Math.round(((w.text+w.li_pl+w.li_pr) - w.pic)/2);
            $('#'+id).css('right',w.diff);
        }
        
    })

    //logo and actions hover
    if(typeof(lang_code) != 'undefined') {
        var path = 'images/'+lang_code+'/';
        var imgsrc = {}

        imgsrc.logo = path+'logo_hover.png';
        imgsrc.actions = path+'actions_hover.png';
        
        var img_hover = new Object;
        for (img in imgsrc){
            img_hover[img] = new Image;
            img_hover[img].src = imgsrc[img];
        }

        $('#logo-map').hover(
            function() {
                temp_image = $('#logo img').attr('src');
                $('#logo img').attr('src',imgsrc.logo);
            },
            function() {
                $('#logo img').attr('src',temp_image);
            })

        $('#actions img').hover(
            function() {
                temp_image = $(this).attr('src');
                $(this).attr('src',imgsrc.actions);
            },
            function() {
                $(this).attr('src',temp_image);
            })
    }

    //portfolio works hover
    $('#works-list li').each(function(){
         $(this).hover(
            function() {
                $(this).find('.image-over').hide();
            },
            function() {
                $(this).find('.image-over').show();
            }
        )
    })


})

function blinking_on(obj) {
    obj.animate({opacity: 0.5}, 200,function() {
        $(this).animate({opacity: 0.7}, 200)
    })
    blinking_on_i = setTimeout(blinking_on,400,obj)
}

function blinking_off(obj) {
    obj.animate({opacity: 1}, 200, function() {
        $(this).css('opacity',1);
    });
}

