//COMPILED mail.js, validate.js, reflection.js
function emdecrypt(a){var f="",d;for(d=0;d<a.length;d+=2)f+=String.fromCharCode(parseInt(a.substr(d,2),16)^d/2);return f}function email(){ahrefs=document.getElementsByTagName("a");nr_ahrefs=ahrefs.length;for(var a=0;a<nr_ahrefs;a++){var f=ahrefs[a];if(f.href.match("#EM#"))f.href="mailto:"+emdecrypt(f.href.replace(/#EM#/g,"").replace("mailto:",""));if(f.innerHTML.match("#EM#"))f.innerHTML=emdecrypt(f.innerHTML.replace(/#EM#/g,""))}}function validate(a,f){var d=f?f:"valid",e=true,b,h,g,i,c;b=0;for(h=a.length;b<h;b++){if(a[b].className.match("fail"))a[b].className=a[b].className.replace(/fail+/gi,"");if(a[b].type=="checkbox")a[b].parentNode.className=a[b].parentNode.className.replace(/fail+/gi,"");if(a[b].getAttribute(d)){var j=a[b].getAttribute(d).split(" ");g=0;for(i=j.length;g<i;g++){c=j[g].split("-");switch(c[0]){case "req":if(!a[b].value.length){a[b].className+=" fail";e=false}break;case "minlen":if(a[b].value.length<c[1]){a[b].className+=" fail";e=false}break;case "maxlen":if(a[b].value.length>c[1]){a[b].className+=" fail";e=false}break;case "len":if(a[b].value.length!=c[1]){a[b].className+=" fail";e=false}break;case "max":if(parseFloat(a[b].value)>parseFloat(c[1])){a[b].className+=" fail";e=false}break;case "min":if(parseFloat(a[b].value)<parseFloat(c[1])){a[b].className+=" fail";e=false}break;case "num":c=/^[0-9]*$/;if(a[b].value.length&&!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "phone":c=/^[ 0-9]*$/;if(!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "notnum":c=/^[0-9]*$/;if(c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "nosp":if(a[b].value.match(" ")){a[b].className+=" fail";e=false}break;case "alp":c=/^[a-zA-Z]*$/;if(a[b].value.length&&!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "alpnum":c=/^[0-9a-zA-Z]*$/;if(a[b].value.length&&!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "date":c=/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/;if(!c.test(a[b].value)&&a[b].value.length){a[b].className+=" fail";e=false}break;case "email":c=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;if(a[b].value.length&&!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "money":c=/^[0-9.,-]*$/;if(a[b].value.length&&!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "checked":if(!a[b].checked){a[b].parentNode.className+=" fail";e=false}break;case "selected":if(a[b].selectedIndex==0){a[b].className+=" fail";e=false}break;case "ip":c=/^([0-9]{0,2})+\.([0-9]{0,2})+\.([0-9]{0,2})+\.([0-9]{0,2})+$/;if(!c.test(a[b].value)){a[b].className+=" fail";e=false}break;case "domain":if(a[b].value.length&&!/^[0-9a-zA-Z.-_]*$/.test(a[b].value)){a[b].className+=" fail";e=false}break;case "size":if(!/^[0-9]*%$/.test(a[b].value)||!/^[0-9]*px$/.test(a[b].value)){a[b].className+=" fail";e=false}break;case "furl":c=/^[a-zA-Z0-9\-]*$/;if(!c.test(a[b].value)||a[b].value.length&&a[b].value.match(" ")){a[b].className+=" fail";e=false}break;case "time":if(a[b].value.length&&!/^[0-9:]*$/.test(a[b].value)){a[b].className+=" fail";e=false}}}}}return e}(function(a){a.fn.extend({reflect:function(f){f=a.extend({height:1/3,opacity:0.5},f);return this.unreflect().each(function(){var d=this;if(/^img$/i.test(d.tagName)){var e=function(){var b=d.width,h=d.height,g,i,c,j;i=Math.floor(f.height>1?Math.min(h,f.height):h*f.height);if(a.browser.msie)g=a("<img />").attr("src",d.src).css({width:b,height:h,marginBottom:i-h,filter:"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+f.opacity*100+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+i/h*100+")"})[0];else{g=a("<canvas />")[0];if(!g.getContext)return;c=g.getContext("2d");try{a(g).attr({width:b,height:i});c.save();c.translate(0,h-1);c.scale(1,-1);c.drawImage(d,0,0,b,h);c.restore();c.globalCompositeOperation="destination-out";j=c.createLinearGradient(0,0,0,i);j.addColorStop(0,"rgba(255, 255, 255, "+(1-f.opacity)+")");j.addColorStop(1,"rgba(255, 255, 255, 1.0)");c.fillStyle=j;c.rect(0,0,b,i);c.fill()}catch(k){return}}a(g).css({display:"block",border:0});g=a(/^a$/i.test(d.parentNode.tagName)?"<span />":"<div />").insertAfter(d).append([d,g])[0];g.className=d.className;a.data(d,"reflected",g.style.cssText=d.style.cssText);a(g).css({width:b,height:h+i,overflow:"hidden"});d.style.cssText="display: block; border: 0px";d.className="reflected"};d.complete?e():a(d).load(e)}})},unreflect:function(){return this.unbind("load").each(function(){var f=a.data(this,"reflected"),d;if(f!==undefined){d=this.parentNode;this.className=d.className;this.style.cssText=f;a.removeData(this,"reflected");d.parentNode.replaceChild(this,d)}})}})})(jQuery);jQuery(function(a){a("img.reflect").reflect({})});
//


/**
 * NOVOSTI
 */
$(document).ready(function(){
    var novosti = $('#novosti .novost');
    var last = $(novosti).first();
    var numbers = $('#novosti .numbers a');
    var interval = setInterval(loopNovosti, 3000);

    $(numbers).each(function(i, el){
        $(el).click(function(e){
            e.preventDefault();
            if(novosti[i] == last[0]) return false;
            showNext($(novosti).eq(i));
            clearInterval(interval);
            interval = setInterval(loopNovosti, 3000);
        });
    });

    function showNext(el){
        $(el).fadeIn();
        $(last).fadeOut();
        last = el;
    }

    function loopNovosti(){
        el = $(last).next('div');
        if(!$(el).length) el = $(novosti).first();
        showNext($(el));
    }    
});

/**
 * LEFT MENU
 */
$(document).ready(function(){
    var head = $('.leftMenuHead');
    $(head).click(function(e){
        $(this).toggleClass('open')
               .next('.leftMenuItems').slideToggle();
    });
});

/**
 *SHOPS
 */
$(document).ready(function(){
    var ul = $('.shops .frame ul');
    var pages = [], p = [];
    $(ul).each(function(i, el){
        pages[i] = $(el).children('li').length-2;
        p[i] = 0;

    });
    var w = $('.shops .frame ul li').outerWidth();
    $('.shops').each(function(i, el){
        if(pages[i] > 0){
            $(el).children('.arrow').click(function(){
                if($(this).hasClass('left')) move(-1, i);
                if($(this).hasClass('right')) move(1, i);
            });
        }else{
            $(el).children('.arrow').toggleClass('dn');
        }
    });

    function move(x, i){
        p[i] += x;
        if(p[i]<0) p[i] = pages[i];
        if(p[i]>pages[i]) p[i] = 0;
        $(ul).eq(i).animate({'margin-left': p[i]*-w+'px'});
    }
});

/**
 * INTRO VIDEOS
 */
$(document).ready(function(){
    var videos = $('#introVideos .slides a');
    var summary = $('#introVideo .right div');
    var lastSum = $('#introVideo .right div').first();
    var player = $('#introPlayer');
    var frame = $('#introPlayerFrame');

    if($(player).length){
        $.getScript(path+'/template/js/swfobject.js', function() {
            showVideo($(videos).first());

        });
    }

    $(videos).each(function(i, el){
        $(el).click(function(e){
            e.preventDefault();
            showSummary(i);
            showVideo($(this));
        });
    });

    function showVideo(el){
        if(!$(player).length) return false;
        $(player).empty();
        //NALOZI VIDEO
        var flashvars = {};
        flashvars.linkfromdisplay = "true";
        flashvars.autostart = "false";
        flashvars.skin = path+"/template/flash/glow.zip";
        flashvars.height = "330";
        flashvars.controlbar = "over";
        flashvars.stretching = "uniform";
        flashvars.width = "440";
        flashvars.repeat = "false";
        flashvars.displayheight = "330";
        flashvars.displaywidth = "440";
        flashvars.image = $(el).attr('rel');
		flashvars.streamer = "rtmp://" + escape("92.244.93.224/oflaDemo/ka3_si/");
		flashvars.file = escape($(el).attr('href'));
        //flashvars.type = "vdox";
        var params = {};
        params.menu = "true";
        params.allowscriptaccess = "always";
        params.allowfullscreen = "true";
        params.wmode= "opaque";
        var attributes = {};
        attributes.id = "introPlayer";
        attributes.name = "video";

        swfobject.embedSWF(path+"/template/flash/player.swf", "introPlayer", "440", "330", "8","expressInstall.swf", flashvars, params, attributes);
        return true;
    }

    function showSummary(i){
        var tmp = $(summary).eq(i);
        $(lastSum).fadeOut();
        $(tmp).fadeIn();
        lastSum = $(tmp);
        return true;
    }
    
});

/**
 * IMAGE REFLECTION
 */
$(document).ready(function(){
    var reflect50 = $('.reflect50');
    $(reflect50).reflect({'height': 50});
});

/**
 * ARTICLES THUMBS
 *
$(document).ready(function(){
    var thumbs = $('.thumb');
    var big = $('.bigImg').first();
    $(thumbs).click(function(e){
        e.preventDefault();        
        var src = $(this).attr('href');
        if(src != $(big).attr('src')){
            $(big).fadeOut(400, function(){
                $(this).attr('src', src)
                       .fadeIn(400);
            });
        }
    });
});
*/


/**
 *FORM
 */
$(document).ready(function(){
    //CUSTOM SUBMIT BUTTON
    var form = $('form');
    $(form).each(function(i, el){
        $(el).contents().find('a.submit').click(function(e){
            e.preventDefault();
            $(el).submit();
        });
    });
});

/**
 *COLORBOX
 */
$(document).ready(function(){
    var pBtn = $(".loginBtn");
    var cb = $("a[rel='colorbox']");
    if(pBtn.length || $(cb).length){
        $.getScript(path+'/template/js/jquery.colorbox-min.js', function() {
            $(pBtn).colorbox({width:"600px", inline:true, href:"#loginForm"});
            $(cb).colorbox({photo:true});
        });
    }
});

/**
 * PRINT
 */
$(document).ready(function(){
    $('.print').click(function(e){
        e.preventDefault();
        window.print();
    });
});

/**
 * LOGIN FORM
 */
$(document).ready(function(){
    login($('#loginForm form'));
});

function login(el){
    $(el).submit(function(e){
        e.preventDefault();
        //setup variables
        var form = $(this),
        formData = form.serialize(),
        responseMsg = $(form).children('.login-response');

        //show response message - waiting
        responseMsg.hide()
                   .text('Prosimo po\u010dakajte...')
                   .fadeIn(200);

        //send data to server for validation
        $.ajax({
            url: form.attr('action'),
            type: form.attr('method'),
            data: form.serialize(),
            success:function(data){
                var responseData = jQuery.parseJSON(data);
                if(!responseData.error) window.location = location.href;
                responseMsg.fadeOut(200,function(){
                    $(this).text(responseData.msg)
                           .fadeIn(200);
                 });
              }
        });
    });
}

/**
 * PLACEHOLDERS
 */
$(document).ready(function(){
    $('input').each(function(i, el){
        if($(el).attr('placeholder') && !$(el).attr('value')){
            $(el).attr('value', $(el).attr('placeholder'))
                 .focusin(function(){
                    if($(this).attr('value') == $(this).attr('placeholder')) $(this).attr('value', '');
                })
                .focusout(function(){
                    if(!$(this).attr('value')) $(this).attr('value', $(this).attr('placeholder'))
                });
        }
    });
});

/**
 * MAIL
 */
$(document).ready(email);
