//browser detektálás
function getInternetExplorerVersion(){
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer'){
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function isFirefox(){
	return ( navigator.userAgent.indexOf('Firefox') > -1 );
}
ie7 = (getInternetExplorerVersion()==7);
ff = isFirefox();

//banner lapozó
bannerRotator = function(name,banner_li,paging,defdel,duration){
    //if($(banner_li).length == 0)return;
    var dd = (defdel && defdel!=0 )?defdel:5000;
    var dur = (!ie7)?(duration?duration:500):0;
    var runpager = true;
    var bl = banner_li;
    var pg = paging?paging:false;
    var pgl = pg?$(pg).length:0;
    var cnt = $(bl).length;
    var current = 0;
    if(cnt<2)return false;
    if(pg){
        $(pg).each(function(k){
            if(k==(pgl-1)){
                $(this).attr('class','selected');
            }
            $(this).children('a').eq(0).attr('href','javascript:'+name+'.pageTo('+(pgl-1-k)+',true);');
        });
    }
    if(!ie7)$(bl).each(function(k){
       if(k==0){
            $(this).css('opacity','1').css('zIndex','2');
       }else{
            $(this).css('opacity','0').css('zIndex','1');
       }
    });
    dy = $(bl).eq(0).attr('value');
    dyp = Math.ceil(Math.random()*3500);
    //console.log(dyp);
    setTimeout(name+'.pageNext()',(dy?(dy*1000):dd)+dyp);
    return{
        pageTo: function(idx,stop){
            if(stop)runpager = false;
            if(idx==current)return;
            if(pg){
                $(pg).each(function(k){
                   if(k==(pgl-idx-1)){
                        $(this).attr('class','selected');
                   }else{
                        $(this).attr('class','');
                   }
                });
            }
            idx = idx%cnt;
            $(bl).eq(current).css('zIndex',1);
            $(bl).eq(idx).css('zIndex',2)
            if(!ie7)$(bl).eq(current).animate({opacity:0},dur);
            if(!ie7)$(bl).eq(idx).animate({opacity:1},dur);
            current = idx;
        },
        pageNext: function(){
            if(!runpager)return;
            nxt = (current+1)%cnt;
            dey = $(bl).eq(nxt).attr('value');
            dey = (dey && dey!=0 )?(dey*1000):dd;
            this.pageTo(nxt);
            setTimeout(name+'.pageNext()',dey+dur);
        }
    }
};

//preloaderek eltüntetése
function removePreloaders(){
    $('.loading').remove();
}

//galériák

galleries = function(_name,selector,_dur){
    var sel = selector;
    var gals = $(selector); 
    var pag = [];
    var dur = _dur;
    var current = -1;
    if (gals.length == 0) return;    
    var def_css = {"height":"580px","margin-bottom":"28px","margin-top":"23px","border-bottom-width": "1px"};
    var hide_css = {"height":"0px","margin-bottom":"0px","margin-top":"0px","border-bottom-width": "0px"};
    var name = _name;
    if (gals.length > 1){
        gals.each(function(k,v){
            pag[k] = 0;
            $(this).css(hide_css);
            $(this).siblings('h2, h3, img, p').css('cursor','pointer').attr("rel",name+".show("+k+");").click(function(){
                eval($(this).attr("rel"));
            });
        });
    }else{
        current = 0;
    }
    gals.each(function(k,v){
        $(this).find("ul.gal li img").css({"opacity":"1"}).load(function(){$(this).animate({"opacity":"1"},500)});
        $(this).find("ul.thumb li img").each(function(kk,vv){
            $(this).attr("rel",name+".pageGal("+kk+")").click(function(){
               eval($(this).attr("rel"));
            });
        });
    });
    
    return {
        show: function(idx){
            if(current==idx){
                gals.eq(current).animate(hide_css,dur);
                current = -1;
            }else{
                if(current!=(-1)) gals.eq(current).animate(hide_css,dur);
                gals.eq(idx).animate(def_css,dur);
                current = idx;
            }
        },
        pageGal: function(to){
            if( to == pag[current]  )return;
            src = gals.eq(current).find("ul.thumb li img").eq(to).attr("src").replace("/45/","/500/");
            fo =  gals.eq(current).find("ul.gal li img");
            fo.animate({opacity:0},dur)
            setTimeout("$('"+sel+" ').eq("+current+").find('ul.gal li img').attr('src','"+src+"');",dur);
            pag[current] = to;
        }
    }
}

var gl;
$(function(){
   gl = new galleries("gl","div.mgaleria",500);
   $('div.glry_title').eq(0).before($('<h1 />').text('Galéria'));
   /*$('div.glry:odd').addClass('even');
   $('div.glry:even').addClass('odd');*/
   if(!FlashDetect.installed){
      $('object').remove();
   }
});

//load esemény
var br_rt;
$(window).load(function(){
    removePreloaders(); 
    //br_rt = new bannerRotator('br_rt','#head_gallery li',false,5000,1000);
    /*$('#head_gallery2').anythingSlider({
        width : 527,
        height: 314,
        easing: 'easeInOutExpo',
        autoPlay            : true,
          startStopped        : false,
          pauseOnHover        : false,
          resumeOnVideoEnd    : false,
          stopAtEnd           : false,
          playRtl             : false,
          startText           : "",
          stopText            : "",
          delay               : 3000,
          animationTime: 600,
          buildArrows         : false
    });*/
    $('#head_gallery2').orbit({animationSpeed: 1000,                // how fast animtions are
     timer: true, 			 // true or false to have the timer
     advanceSpeed: 15000});
});

var FlashDetect=new function(){var self=this;self.installed=false;self.raw="";self.major=-1;self.minor=-1;self.revision=-1;self.revisionStr="";var activeXDetectRules=[{"name":"ShockwaveFlash.ShockwaveFlash.7","version":function(obj){return getActiveXVersion(obj);}},{"name":"ShockwaveFlash.ShockwaveFlash.6","version":function(obj){var version="6,0,21";try{obj.AllowScriptAccess="always";version=getActiveXVersion(obj);}catch(err){}
return version;}},{"name":"ShockwaveFlash.ShockwaveFlash","version":function(obj){return getActiveXVersion(obj);}}];var getActiveXVersion=function(activeXObj){var version=-1;try{version=activeXObj.GetVariable("$version");}catch(err){}
return version;};var getActiveXObject=function(name){var obj=-1;try{obj=new ActiveXObject(name);}catch(err){obj={activeXError:true};}
return obj;};var parseActiveXVersion=function(str){var versionArray=str.split(",");return{"raw":str,"major":parseInt(versionArray[0].split(" ")[1],10),"minor":parseInt(versionArray[1],10),"revision":parseInt(versionArray[2],10),"revisionStr":versionArray[2]};};var parseStandardVersion=function(str){var descParts=str.split(/ +/);var majorMinor=descParts[2].split(/\./);var revisionStr=descParts[3];return{"raw":str,"major":parseInt(majorMinor[0],10),"minor":parseInt(majorMinor[1],10),"revisionStr":revisionStr,"revision":parseRevisionStrToInt(revisionStr)};};var parseRevisionStrToInt=function(str){return parseInt(str.replace(/[a-zA-Z]/g,""),10)||self.revision;};self.majorAtLeast=function(version){return self.major>=version;};self.minorAtLeast=function(version){return self.minor>=version;};self.revisionAtLeast=function(version){return self.revision>=version;};self.versionAtLeast=function(major){var properties=[self.major,self.minor,self.revision];var len=Math.min(properties.length,arguments.length);for(i=0;i<len;i++){if(properties[i]>=arguments[i]){if(i+1<len&&properties[i]==arguments[i]){continue;}else{return true;}}else{return false;}}};self.FlashDetect=function(){if(navigator.plugins&&navigator.plugins.length>0){var type='application/x-shockwave-flash';var mimeTypes=navigator.mimeTypes;if(mimeTypes&&mimeTypes[type]&&mimeTypes[type].enabledPlugin&&mimeTypes[type].enabledPlugin.description){var version=mimeTypes[type].enabledPlugin.description;var versionObj=parseStandardVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revisionStr=versionObj.revisionStr;self.revision=versionObj.revision;self.installed=true;}}else if(navigator.appVersion.indexOf("Mac")==-1&&window.execScript){var version=-1;for(var i=0;i<activeXDetectRules.length&&version==-1;i++){var obj=getActiveXObject(activeXDetectRules[i].name);if(!obj.activeXError){self.installed=true;version=activeXDetectRules[i].version(obj);if(version!=-1){var versionObj=parseActiveXVersion(version);self.raw=versionObj.raw;self.major=versionObj.major;self.minor=versionObj.minor;self.revision=versionObj.revision;self.revisionStr=versionObj.revisionStr;}}}}}();};FlashDetect.JS_RELEASE="1.0.4";

