$curla='en';
$posli=10;
$sideshow=false;

$Pa='home';


$(document).ready(function(){
    $('span.lang').children(":not([lang="+$curla+"])").hide();
    $('div.menk_top').menu();
    $('.waiting').hide();
    //contch(Pa);
});
function jsphp(fn,val1,val2){
    out='';
    $.ajax({type: "POST",
        url: 'js.php',
        async: false,
        data: {fn: fn,val1: val1,val:val2},
        success:  function(data){
            out= data;
        }});
    return out;
}
(function($) {
    $.fn.menu = function(set){
        var c = {
            speed: 200
        };
        
        return this.each(function(){
            
            //$(this).mact();
            $(this).children('div.menk').each(function(){
                if ($(this).children('div.kastext').length){
                    var p=$(this).children('div.kastext').position();
                    $(this).children('div.kastexb')
                        .height($(this).children('div.kastext').height())
                        .width($(this).children('div.kastext').width())
                        .css({'top':p.top+'px','left':p.left+'px'});
                }
                $(this).children('div.bbg')
                    .width($(this).children('div.kastext').width() + 25);
                $(this)
                .hoverIntent({over:function(){
                        $(this).siblings('div.menk').umact();
                        $(this).mact();
                       },
                    out:function(){
                    },
                    timeout:0}
                )
                .click(function(){
                    $Pa=$(this).attr('id');
                    $(this).chan();
                })
                    ;
            });
            $(this)
            .hoverIntent({over:function(){
                   },
                out:function(){
                        $(this).children('div.menk.act').mact();
                    $(this).children('div.menk:not(.act)').umact();
                    //$(this).not('.act').umact();
                },
                timeout:0}
            )
            //var Pa = $("input.Page").val();
            $(this).children('div.menk#'+$Pa).chan().mact().siblings('div.menk').mact({start: true});
        });
    };
    $.fn.chan = function(set){
        var c = {
            speed: 200
        };
        if (typeof set=='number'){
            c.speed=set;
        } else {
            c = $.extend(c, set);
        }
        return this.each(function(){
            if ($(this).children('div.kastext').length){
                if (!$(this).hasClass('act')){
                    $(this).addClass('act').mact(0);
                    $("input.Page").val($(this).attr('id'));
                    $(this).siblings('div.menk').removeClass('act').umact();
                    
                }
                if ($(this).attr('id')=='home'){
                    $("div.backg").animate({ 
                        left: "10px"
                      }, 1000 );
                } else {
                    $("div.backg").animate({ 
                      left: "-400px"
                    }, 1000);
                }

                $ctyp=$(this).attr('typ');
                window.scrollTo(0,0);
                $("div.inhalt").hide(0,function(){if ($ctyp=='img') $('.waiting').show();});
                
                    $('img.pause').hide().siblings('img.play').show();
                window.clearInterval($sideshow);
                $.ajax({type: "POST",
                    url: "content.php",
                    async: false,
                    data: {id: $(this).attr('id'),typ: $ctyp, adm: $adm},
                    success:  function(data){
                        $("div.inhalt").html(data);
                        if ($ctyp=='img'){
                            done=false;
                            $("div.inhalt").find('img').last().load(function(){
                                
                               $('.waiting').hide();
                               $("div.inhalt").fadeIn(500);
                               });
                            if (done==true){}
                        } else {
                           $('.waiting').hide();
                           $("div.inhalt").fadeIn(500);
                        }
                }});
                //$.post("content.php", {id: $(this).attr('id'),typ: $ctyp, adm: $adm}, function(data){
                //});
            }
        });
    };
    $.fn.mact = function(set){
        var c = {
            speed: 200,
            start: false
        };
        if (typeof set=='number'){
            c.speed=set;
        } else {
            c = $.extend(c, set);
        }
        return this.each(function(){
            if (c.start===false){
                $(this).children('div.sq')
                    .css({'zIndex':9})
                    .animate({left:'-4px',top:'-4px',width:'25px',height:'25px'},c.speed)
                    ;
                
            }
            if ($adm==0){
                $(this).children('div.kastexb').fadeIn(c.speed);
                $(this).children('div.kastext').fadeIn(c.speed);
            }
        });
    };
    $.fn.umact = function(set){
        var c = {
            speed: 0
        };
        c = $.extend(c, set);
        return this.each(function(){
            $(this).children('div.sq')
            .css({'zIndex':2})
            .css({left:'0px',top:'0px',width:'17px',height:'17px'});
            $(this).not('.act').children('div.sq')
            .css({'zIndex':1})
            ;
            if ($adm==0){
                $(this).children('div.kastexb').fadeOut(c.speed);
                $(this).children('div.kastext').fadeOut(c.speed);
            }
        });
    }
    $.fn.imzoom = function(set){//$('div.imgoverv').imzoom();
        var c = {
            speed: 300,
            ed:false
        };
        c = $.extend(c, set);
        return this.find('div.tabimg').each(function(){
                $(this).children('img.tabimg').hover(
                    function(){
                        $(this).css({'zIndex':3})
                        .animate({left:'-25px',top:'-25px',width:'100px',height:'100px'},c.speed)
                        ;
                    },
                    function(){
                        $(this).css({'zIndex':2})
                        .animate({left:'0px',top:'0px',width:'50px',height:'50px'},c.speed)
                        .css({'zIndex':0});
                    }
                )
                if (c.ed===false)
                $(this).children('img.tabimg').click(function(){
                    $nobj=$(this).closest('div.tabimg');
                    //var ids=$nobj.attr('idd');
                    //var ipath=$opath+ids;
                    $(this).closest('div.imgoverv').siblings('table.imgbig')
                    .imch(c.speed);
                    //if ($nobj.attr('num')=='0')
                    //    tab.find('img.obj_prev').hide();
                    //else
                    //    tab.find('img.obj_prev').show();
                    //if ($nobj.attr('num')==$(this).closest('div.tabimg').last().attr('num'))
                    //    tab.find('img.obj_next').hide();
                    //else
                    //    tab.find('img.obj_next').show();
                    //tab.find('img.mainobj').attr('src',$opath+$nobj.attr('idd')).attr('idd',$nobj.attr('idd')).show();
                    $(this).closest('div.imgoverv').slideUp(c.speed).siblings('table.imgbig').slideDown(c.speed);
                })
                ;
        });
    }
    $.fn.imtab = function(set){//$(table.imgbig').imtab();
        var c = {
            speed: 300,
            sidespeed:3000
        };
        c = $.extend(c, set);
        return this.each(function(){
                $(this).find('img.play')
                .click(function(){
                    $(this).hide().siblings('img.pause').show();
                    $('table.imgbig').children(':first').imch(c.speed,true);
                    $sideshow=window.setInterval(function(){  $('table.imgbig').children(':first').imch(c.speed,true);},c.sidespeed);
                })
                ;
                $(this).find('img.pause').hide()
                .click(function(){
                    $('img.pause').hide().siblings('img.play').show();
                    window.clearInterval($sideshow);
                })
                ;
                $(this).find('img.obj_prev')
                .click(function(){
                    $(this).imch(
                        c.speed,false
                    );
                })
                ;
                $(this).find('img.obj_next')
                .click(function(){
                    $(this).imch(
                        c.speed,true
                    );
                })
                ;
                $(this).find('img.mainobj')
                .click(function(){
                    $(this).imch(
                        c.speed,true
                    );
                })
                ;
                $(this).find('a.obj_over')
                .click(function(){
                    $('img.pause').hide().siblings('img.play').show();
                    window.clearInterval($sideshow);
                    $(this).closest('table.imgbig').slideUp(c.speed).siblings('div.imgoverv').slideDown(c.speed);
                })
                ;
        });
    }
    $.fn.imch = function(s,next){//any in $(table.imgbig')
        return this.closest('table.imgbig').each(function(){
            num=parseInt($nobj.attr('num'));
            lnum=parseInt($nobj.closest('div.imgoverv').find('div.tabimg').last('.tabimg').attr('num'));
            if (next===false && num!=0)
                if ($nobj.prev().is('br'))
                $nobj=$nobj.prev().prev('.tabimg');
                else
                $nobj=$nobj.prev('.tabimg');
            else if (next===true && num!=lnum){
                if ($nobj.next().is('br'))
                $nobj=$nobj.next().next('.tabimg');
                else
                $nobj=$nobj.next('.tabimg');
            }
            else if (next===undefined)
                $nobj=$nobj;
            else {
                  $nobj=$nobj.parent().children('div.tabimg:first-child');
                  
                  
            }
            
            if ($nobj!=false){
                var nnum=parseInt($nobj.attr('num'));
                if (nnum==0)
                    $(this).find('img.obj_prev').hide();
                else
                    $(this).find('img.obj_prev').show();
                if (nnum==lnum){
                    //$sideshow=clearInterval($sideshow);
                    //$('img.pause').hide().siblings('img.play').show();
                    $(this).find('img.obj_next').hide();
                }
                else 
                    $(this).find('img.obj_next').show();
                $(this).find('img.mainobj')
                .fadeOut(s,function(){
                    $(this).attr('src',$opath+$nobj.attr('idd')+'.'+$nobj.attr('ityp'))
                    .attr('idd',$nobj.attr('idd'))
                    .load(function() {
                        $(this).fadeIn(s);
                    });
                });
            }
        });
    }
    
})(jQuery);
