jQuery(document).ready(function(){
var cookie

//jQuery('#wrapper2').css('height',jQuery('body').innerWidth())

var starttime = (new Date).getTime();
 
var no_animation =  0
if(jQuery.cookie('no_animation')){
    no_animation=jQuery.cookie('no_animation')
}


jQuery('.stop_anim').click(function(){

      no_animation = 1;
//      console.log('stop',no_animation);
      jQuery.cookie('no_animation','1',{
            path:'/'
        });

        return false
})
jQuery('.start_anim').click(function(){

     no_animation = 0;
//      console.log('start');
     jQuery.cookie('no_animation','0',{
            path:'/'
        });

        return false
})


// photo's fade-in after click or hover
   jQuery('.e_ph').hover(function(){

        jQuery('#'+jQuery(this).attr('target')).css('z-index',1)

    //alert('#'+$(this).attr('title'))

    },function(){

        //alert($(this).attr('title'))
       jQuery('#'+jQuery(this).attr('target')).css('z-index','')

    }

    )

    jQuery('.e_ph').click(function(){
       
        return false
    })

    //empty menu`s
    jQuery('.nolink > a').click(function(){
     
        return false
    })


     jQuery('img.radius').wrap(function() {
  return '<div class="radius" style="background-image:url('+ jQuery(this).attr('src') +')" />';
});



    function floatimgs(id,dx,dy,speed,x,y,i){
        var min_x=-200-(window.innerWidth-1024)/2
        var min_y=-300
        var max_x=(window.innerWidth-1024)/2+1024-300;
        var max_y=document.body.scrollHeight-200
        var id = jQuery(id);
        var dx = dx;
        var dy = dy;
        var x=x;
        var y=y;
        id.css('left',x)
        id.css('top',y)

        var speed = speed;
        move = function (){
          if(no_animation==1) return
      
            if(x < min_x) dx=Math.abs(dx)
            if(x > max_x) dx=-Math.abs(dx)
            if(y < min_y) dy=Math.abs(dy)
            if(y > max_y) dy=-Math.abs(dy)
            x+=dx
            y+=dy
            cookie.floats[i].x=x
            cookie.floats[i].dx=dx
            cookie.floats[i].speed=speed
            cookie.floats[i].y=y
            cookie.floats[i].dy=dy
          
            id.animate(
            {
                top:'+='+dy+'px',
                left:'+='+dx+'px'
            },speed);
         
        }

        start = function(){
          setInterval(move,speed)
        }
        exportpos = function(){
            return({
                x:x,
                y:y,
                dx:dx,
                dy:dy

            })
        }
        start()

    }

    if(jQuery.cookie('imgfloat')){
         cookie = JSON.parse(jQuery.cookie('imgfloat'))


for (var i in cookie.floats){
        new floatimgs('#'+cookie.floats[i].id,cookie.floats[i].dx,cookie.floats[i].dy,cookie.floats[i].speed,cookie.floats[i].x,cookie.floats[i].y,i)


    }
    }
    else{
         cookie = {
            floats:
            [
            {
                id:'vorm1',
                x:-250,
                y:350,
                dy:-2,
                dx:1,
                speed:200
            },

            {
                id:'vorm2',
                x:500,
                y:350,
                dy:1,
                dx:1,
                speed:200
            },

            {
                id:'vorm3',
                x:750,
                y:350,
                dy:-1,
                dx:-1,
                speed:200
            },

            {
                id:'vorm4',
                x:-270,
                y:540,
                dy:-1,
                dx:2,
                speed:200
            },

            {
                id:'vorm5',
                x:110,
                y:520,
                dy:1,
                dx:-1,
                speed:200
            },

            {
                id:'vorm6',
                x:500,
                y:570,
                dy:-1,
                dx:-2,
                speed:200
            },

            {
                id:'vorm7',
                x:850,
                y:520,
                dy:2,
                dx:1,
                speed:200
            }
            ]

        }
    
    setTimeout(function(){
    for (var i in cookie.floats){
        new floatimgs('#'+cookie.floats[i].id,cookie.floats[i].dx,cookie.floats[i].dy,cookie.floats[i].speed,cookie.floats[i].x,cookie.floats[i].y,i)
    
    
    }},3000)


    }

       jQuery(window).unload(function(){

        jQuery.cookie('imgfloat',JSON.stringify(cookie),{
            path:'/',expires:1
        });


    })

 // animation start/stop




})


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


