/*   */

// Global Variables
var loadedOnes = new Array();
var globalx = 0;
var globaly = 0;
var iamiphone = 0;
var countclicks = 0;

function indexInArray(arr,val){
    for(var i=0;i<arr.length;i++) if(arr[i]==val) return i;
    return -1;
}
//
function dothis(me, what) {
    ox = globalx-1000;
    oy = globaly-600;

    switch (me) {

        case 1: x=0; y=0; break;
        
        case 2: x=2000; y=0; break;
        case 3: x=2000; y=1000; break;
        case 4: x=2000; y=2000; break;
        
        case 5: x=4000; y=0; break;
        case 6: x=4000; y=1000; break;
        case 7: x=4000; y=2000; break;

        case 8: x=6000; y=0; break;
        case 9: x=6000; y=1000; break;

        case 10: x=8000; y=0; break;
        case 11: x=8000; y=1000; break;
    }

    if (indexInArray(loadedOnes,me) == -1) {
        loadedOnes.push(me);
        $("#b" + me).load("bildbackgrounds/b" + me + ".php",0);
    }

    
    x = x-ox/2;
    y = y-oy/2;
    if (what == "first") {
        $("#sidebody").css( { left:  -x + "px", top:  -y + "px"  });
        dontmove = 0;
    } else {
        if (dontmove==0) {
        /*

            var dura = 1600;
            var dura = 1600 -(50*countclicks);
            if (dura<=400)
                countclicks--;
            } else {
                countclicks++;
            }
        */
            $("#sidebody").animate( { left:  -x + "px", top:  -y + "px"  }, { queue:false, duration: 1600 } );
        }
    }  
}
//
function theresize(bwidth,bheight) {
    if (iamiphone!=1) {
        var ymax=screen.availHeight;
        var xmax=screen.availWidth;
        self.moveTo(0,0);
        window.resizeTo(xmax,ymax);
    //
        var x,y;
        if (self.innerHeight) // all except Explorer
        {
            x = self.innerWidth;
            y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
            // Explorer 6 Strict Mode
        {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
        }
        else if (document.body) // other Explorers
        {
            x = document.body.clientWidth;
            y = document.body.clientHeight;
        }
        
        ymaxdiff=ymax-y;
        xmaxdiff=xmax-x;
        globaly = y;
        globalx = x;
    } else {
        alert("iphone");
        globalx = 1000;
        globaly = 600;
    }
    dothis(1, "first");
}



function changenews(what) {
    $("#aktuelles").fadeOut('fast',function(){
        $("#loadergif").fadeIn('slow');
        $("#aktuelles").load(what,0,function(){
            $("#loadergif").fadeOut('slow');
            $("#aktuelles").fadeIn('slow');
        });
    });
}


  $(document).ready(function(){
    var validator = $("#myForm").validate({
        rules: { 
            name: { 
                required: true,
                minlength:2
            },
            email: {
                required:true,
                email:true
            }
        },
        messages: { 
            name: "Geben Sie bitte Ihren Namen ein", 
            email: "Geben Sie bitte Ihre E-Mailadresse ein"
        }, submitHandler: function(){
                jQuery("#myForm").ajaxSubmit({
					target: "#formbox"
				});
        }
    }); // validator ends here
});

