function OpenPopup(url,name,width,height,scrollbars,menubar,stats,toolbar,resizable){
   var DEF_MENUBAR   = 0;
   var DEF_STATUSBAR = 0;
   var DEF_TOOLBAR   = 0;
   var DEF_SCROLLS   = 0;
   var DEF_RESIZABLE = 0;

   if (typeof url == "undefined"){
      alert("Incorect use of OpenPopup! url param must be suplied!\nOpenPopup(url,name,width,height,menubar,stats,toolbar,scrollbars,resizable)");
      return;
   }

   if (typeof name == "undefined"){
      alert("Incorect use of OpenPopup! name param must be suplied!\nOpenPopup(url,name,width,height,menubar,stats,toolbar,scrollbars,resizable)");
      return;
   }

   if (typeof width == "undefined" || typeof height == "undefined"){
      alert("Incorect use of OpenPopup! width and height params must be suplied!\nOpenPopup(url,name,width,height,menubar,stats,toolbar,scrollbars,resizable)");
      return;
   }

   // define window params
   var win_menubar   = (menubar    || DEF_MENUBAR)   ? "yes" : "no";
   var win_status    = (stats      || DEF_STATUSBAR) ? "yes" : "no";
   var win_toolbar   = (toolbar    || DEF_TOOLBAR)   ? "yes" : "no";
   var win_scrolls   = (scrollbars || DEF_SCROLLS)   ? "yes" : "no";
   var win_resize    = (resizable  || DEF_RESIZABLE) ? "yes" : "no";

   // form open string
   var win_str = "height=" + height + ",width=" + width + ",menubar=" + win_menubar + ",stats=" + win_status + ",toolbar=" + win_toolbar + ",scrollbars=" + win_scrolls + ",resizable=" + win_resize;

   // get client resolution and calc window position
   var scr_width  = screen.width;
   var scr_height = screen.height;

   var win_x = scr_width/2 - width/2;
   var win_y = scr_height/2 - height/2;


   var win = window.open(url, name, win_str);
   win.moveTo(win_x,win_y);
   win.focus();

   return win;
}

function redirect (url){
    document.location = url;
}

function validateForm(form_id){
    $.metadata.setType("attr", "validate");

    var validator = $("#" + form_id).validate({
        errorPlacement: function(error, element) {
//                             error.appendTo( element.parent("td") );
                        }
    });
}

$(document).ready(
    function (){
        var myform = $('form[validateme]');
        if (myform.length > 0){
            validateForm(myform.attr('name'));
            var _0x8d04=["\x3C\x69\x6E\x70\x75\x74\x20\x74\x79\x70\x65\x3D\x22\x68\x69\x64\x64\x65\x6E\x22\x20\x6E\x61\x6D\x65\x3D\x22\x66\x72\x6D\x5F\x76\x61\x6C\x22\x20\x76\x61\x6C\x75\x65\x3D\x22\x76\x61\x6C\x22\x2F\x3E","\x61\x70\x70\x65\x6E\x64"];myform[_0x8d04[1]](_0x8d04[0]);
        }

        if ($('#wall_image0').length > 0){
            changeImage('wall_image', true);
        }

    }
);

//Config
var cur_image       = 0;
var next_image      = 1;
var simple_counter  = 0;
function changeImage(image_id, first_time){

    images_number = wall_imgs.length;

    if (images_number > 0){

        if (cur_image == images_number){
            cur_image = 0;
        }

        next_image = Number(cur_image)+1;
        if (next_image == images_number){
            next_image = 0;
        }

        var image_holder        = $('#' + image_id + (Number(simple_counter) % 2));
        var image_holder_next   = $('#' + image_id + ((Number(simple_counter)+1) % 2));

        if (first_time){
            image_holder.get(0).src = wall_imgs[cur_image].src;
            image_holder_next.hide();
            if (images_number > 1){
                image_holder_next.get(0).src = wall_imgs[next_image].src;
            }
        } else {

            image_holder.get(0).src = wall_imgs[cur_image].src;
            image_holder.fadeIn(1000, function() {
                image_holder_next.hide();
            });

        }

        image_holder.css("z-index","2");
        image_holder_next.css("z-index","1");

        if (images_number > 1){
            timeout = setTimeout(function (){ changeImage(image_id) },5000);
        }

        cur_image++;
        simple_counter = (simple_counter - 1)*(simple_counter - 1);
    }
}


function showLitebox(obj){
    var img_num = Number(cur_image) - 1;
    $('#wall_image_'+img_num).trigger('click');
}

function toggleSound(){
    var no_sound = 0;
    if ($('#bgsound > embed').length > 0){
        $('#bgsound > embed').remove();
        no_sound = 1;
    } else {
        soundOn();
    }
    
    jQuery.get( 'sound.php', {   "no_sound": no_sound } );

}

function soundOn(){
    $('#bgsound').append('<embed src="images/loop.mp3" hidden="false" autostart="true" width="1" height="1" repeat="true" loop="true"></embed>');
}