$(document).ready(function(){
 
 $('#gitmail').html( $('<a>').attr('href','mailto'+':'+'info'+'@'+'xyberdyn'+'.'+'com').html('info'+'@'+'xyberdyn'+'.'+'com') );
 $('#gitvcard').children('a').attr('href','/'+'dl'+'/'+'Mar'+'io_Sch'+'wennicke'+'.'+'vc'+'f');
 
 seton();
 
 
 $('.xdhead ul li,.weboxes div h3,.aboutinfo div').xdVslider();
 inhoSlide = false;
 iwidth = $('.inhoslidei').width();
 bwidth = $('.inhoslidei').parent().width();
 $('#inhoprev').xdINHOprev();
 $('#inhonext').xdINHOnext();
 
 if(caton == 2000){
  $(window).bind('scrollstart',function(){ $('.xdhead').children('ul').children('li').css('background-image','url(/img/x5tpmbg.png)').children('a').css('color',''); });
  $(window).bind('scrollstop',function(){ seton();
                                        });
 }
 
 
 $('#inhoprev,#inhonext').hover(function(){ if($(this).attr('src').indexOf('off') <= 0) $(this).attr('src',$(this).attr('src').replace(/.png/,'ov.png')); }
                               ,function(){ if($(this).attr('src').indexOf('off') <= 0) $(this).attr('src',$(this).attr('src').replace(/ov.png/,'.png')); });
 $('#inhoslide').xdINHOSlideFix();
 $('.inhoshots img').click(function(){ xdINHOsel($(this).index()); });
 
 xdsiopen = false;
 $('#xdsignin').click(function(){ if(!xdsiopen && xdiUserID == 0){
	                               xdsiopen = true;
	                               var orghtml = $(this).html();
	                               $(this).css('cursor','auto');
                                   $(this).css({'background-image':'url(/img/x5tpmbgon.png)','opacity':'0.3'})
	                                      .fadeTo('slow',1,function(){ $(this).animate({'width':'145px','height':'180px'},'fast'
	                                     		                              ,function(){ $.get('/index.php',{'dyn':'xdsi', 'nocache' : Math.random()}
	                                    		                                            ,function(res){ $('#xdsignin').append($(res)); 
	                                    		                                                            $('#xdsiclose').click(function(){ $('#xdsignin').html('')
	                                    		                                                        	                                                .animate({'width':'30px','height':'20px'},'fast'
	                                    		                                                        		                                                    ,function(){ $('#xdsignin').css({'width':'auto','height':'','background-image':'url(/img/x5tpmbg.png)','cursor':'pointer'}).html(orghtml); xdsiopen = false; });
	                                    		                                                                                              return false;
	                                    		                                                                                            }); 
	                                    		                                                          }); 
	                                    		                                         }); 
	                                                                 }); 
                                  }
                                 }).xdUmenu();
 $('#xdumenu').xdUmenu();
});

jQuery.fn.xdUmenu = function() {
 return this.hover(function(){ if($('#xdumenu').length > 0){
	                            var pos = $('#xdsignin').offset().top + $('#xdsignin').height() +5;
	                            $('#xdumenu').css({'top':pos,'display':'block'});
                               }
                             }
                  ,function(){ if($('#xdumenu').length > 0){
                	            $('#xdumenu').css({'display':'none'});
                               }
                             });
}

jQuery.fn.xdVslider = function() {
 return this.click(function(){ if($(this).children('a').attr('href').substr(0,1) == "/"){
	                            window.location.href = $(this).children('a').attr('href');
                               }
                               else{
	                            var id = $(this).children('a').attr('href').substr(1);
                                var pos = $('#'+id).position();
                                $('html,body').animate({scrollTop:pos.top},1000,function(){  });
                                return false;
                               }
                             });
}

jQuery.fn.xdINHOprev = function() {
 return this.click(function(){ var sleft = $('#inhoslide').scrollLeft();
                               xdINHOsel(((sleft==0?iwidth:sleft)/iwidth)-1);
                             });
}

jQuery.fn.xdINHOnext = function() {
 return this.click(function(){ var sleft = $('#inhoslide').scrollLeft();
                               xdINHOsel((sleft==0?0:sleft/iwidth)+1);
                             });
}

jQuery.fn.xdINHOSlideFix = function() {
 return this.bind('scrollstop',function(){ xdINHOsel(Math.round($('#inhoslide').scrollLeft()/iwidth)); });
}

function xdINHOsel(nr) {
 var sleftnew = iwidth*nr;
 if(inhoSlide == false && sleftnew >= 0 && sleftnew < bwidth){
  inhoSlide = true;

  $('.inhoshots').children('img').css('border-top-color','#ffffff');
  $('.inhoshots img:nth-child('+(nr+1)+')').css('border-top-color','#f5a23e');
  $('#inhoslide').animate({scrollLeft:sleftnew},500,function(){ inhoSlide = false;
                                                                if(sleftnew == 0) $('#inhoprev').attr('src','/img/prevoff.png');
                                                                else if(sleftnew > 0 && $('#inhoprev').attr('src') == '/img/prevoff.png') $('#inhoprev').attr('src','/img/prev.png');
                                                                if(sleftnew >= bwidth - iwidth) $('#inhonext').attr('src','/img/nextoff.png');
                                                                else if(sleftnew < bwidth - iwidth && $('#inhonext').attr('src') == '/img/nextoff.png') $('#inhonext').attr('src','/img/next.png');
                                                              });
 }
}

function seton(){
 var stop = $(document).scrollTop();
 var active = 'start';
 $('.xdhead').parent().children('div')
             .each(function(){ var id = $(this).attr('id');
                               if(id){
                                var ipos = $(this).position().top - 100;
                                var iheight = $(this).outerHeight();
                                if(stop >= ipos && stop <= ipos+iheight) active = id;
                                
                               }
                             });
 $('#b'+active).css({'background-image':'url(/img/x5tpmbgon.png)','opacity':'0.3'}).children('a').css('color','#ffffff').parent().fadeTo('slow',1);
}



var xdTemp = "";
var xdDC = new Array();

function xdStart(hostData,sid) {
 
}

var sK = "";
var tK = "";

function xdDCL(sKey,tKey,dKey,get,fresh,lSign,oc) {
 sK = sKey;
 tK = tKey == "" ? sKey : tKey;
 var isOn = 1;
 var tObj = document.getElementById(tK);
 if(oc != ""){
  if(tObj.style.display == "none"){
   tObj.style.display = "block";
  }
  else{
   tObj.style.display = "none";
   isOn = 0;
  }
 }
 if(isOn == 1){
  if(!xdDC[sK] || xdDC[sK] == "" || fresh != ""){
   if(lSign != "") tObj.innerHTML = getLoadSign();
   sendRequest( "/"+dKey, "dyn="+tKey+get+"&nocache="+Math.random(), 0, "xdDCLR" );
  }
  else{
   tObj.innerHTML = xdDC[sK];
  }
 }
}

function xdDCLR(res) {
 xdDC[sK] = res;
 document.getElementById(tK).innerHTML = res;
}




function xdFormLoading(fID) {
 //alert("StartFunc");
 document.getElementById("xdform"+fID).style.display = "none";
 var obj = document.getElementById("xdformstate"+fID);
 obj.innerHTML = getLoadSign();
 obj.style.display = "block";
 
 return true;
}

function getLoadSign() {
 return "<center><div style=\"width:30px;height:30px;background-color:#ffffff;\"><img src=\"/img/load/loadani.gif\" align=\"top\" style=\"margin:6px 6px 6px 6px;\"/></div></center>";
}



(function(){
	 
    var special = jQuery.event.special,
        uid1 = 'D' + (+new Date()),
        uid2 = 'D' + (+new Date() + 1);
 
    special.scrollstart = {
        setup: function() {
 
            var timer,
                handler =  function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    } else {
                        evt.type = 'scrollstart';
                        jQuery.event.handle.apply(_self, _args);
                    }
 
                    timer = setTimeout( function(){
                        timer = null;
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid1, handler);
 
        },
        teardown: function(){
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
        }
    };
 
    special.scrollstop = {
        latency: 300,
        setup: function() {
 
            var timer,
                    handler = function(evt) {
 
                    var _self = this,
                        _args = arguments;
 
                    if (timer) {
                        clearTimeout(timer);
                    }
 
                    timer = setTimeout( function(){
 
                        timer = null;
                        evt.type = 'scrollstop';
                        jQuery.event.handle.apply(_self, _args);
 
                    }, special.scrollstop.latency);
 
                };
 
            jQuery(this).bind('scroll', handler).data(uid2, handler);
 
        },
        teardown: function() {
            jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
        }
    };
 
})();
