function openURL(url) {
    //window.location.href = '/out_'+url;
    window.open('/out_'+url);
}

// MENU -----------------------
var menu = {};

menu.showSubmenu = function(id) {
    $("#sub_menu").fadeOut(1000,
      function() {
        document.getElementById('sub_menu').innerHTML = document.getElementById('submenu'+id).innerHTML;
        $("#sub_menu").fadeIn(1000);
    });
    $('#leftcol_sub_content').fadeOut(1000);
}

menu.showSubSubmenu = function(id) {
    $('.submenuitem_ac').removeClass('aktive').removeClass('submenuitem_ac');
    $('#submenuitem-'+id).addClass('aktive').addClass('submenuitem_ac');
    $('#leftcol_sub_content').hide('fast',
      function() {
        document.getElementById('leftcol_sub_content').innerHTML = document.getElementById('subsubmenu'+id).innerHTML;
        $('#leftcol_sub_content').fadeIn(500);
    });
}

// INTRO -----------------------------------------------------------
var intro = {};

intro.animate = function() {
    var ua = navigator.userAgent;
    var IEoffset = ua.indexOf("MSIE ");
    var MSIEVersionNumber = parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
    if (MSIEVersionNumber < 7) {
    //if ((jQuery.browser.msie==true) && (jQuery.browser.version.substr(0, 1)=='6')) {
        alert("Вы используете устаревший браузер Internet Explorer 6, некоторые элементы сайта могут отображаться некорректно! Обновите, пожалуйста, Internet Explorer до версии 8 или воспользуйтель альтернативным браузером, например, Firefox 3.5");
    }

    $("#page").fadeIn(1500,
                       function() {
                           $("#asb1").fadeIn(1000); $("#ast1").fadeIn(500,
                           function() {$("#asb2").fadeIn(1000); $("#ast2").fadeIn(500,
                           function() {$("#asb3").fadeIn(1000); $("#ast3").fadeIn(500,
                           function() {$("#asb4").fadeIn(1000); $("#ast4").fadeIn(500,
                           function() {$("#asb5").fadeIn(1000); $("#ast5").fadeIn(500,
                           //function() {$('.delimiter').animate({fontSize: "10px"}, 1500, function() {
                           function() {$('.delimiter').css('visibility', 'visible'); $('.delimiter').fadeIn(1000/*, function() {
                                                               $('.delimiter').html('<img src="/img/submenu_delimiter.gif" width="2" height="12" alt="" />');
                           }*/);}
                           //function() {$('.delimiter_img').animate({height: "12px"}, 1000);}
                           );});});});
                                            });
                           document.getElementById('bmenu').style.display='block';
                           $("#cp").fadeIn(1000);
                       });
}

intro.lastShowedSubmenuId = 0;

intro.showSubmenu = function(id) {
    if (intro.lastShowedSubmenuId != 0) {
        $('#submenu'+intro.lastShowedSubmenuId).fadeOut(1000);
        //$('#delimiter'+intro.lastShowedSubmenuId).html('<img src="/img/submenu_delimiter.gif" width="2" height="12" alt="" />');
        $('#delimiter'+intro.lastShowedSubmenuId).css('visibility', 'visible');
    }
    var ua = navigator.userAgent;
    var IEoffset = ua.indexOf("MSIE ");
    if (IEoffset == (-1)) {
        $('#submenu'+id).fadeIn(1000);
    } else {
        var MSIEVersionNumber = parseFloat(ua.substring(IEoffset+5, ua.indexOf(";", IEoffset)));
        if (MSIEVersionNumber < 8) {
            $('#submenu'+id).fadeIn(1000);
        } else {
            $('#submenu'+id).css('display', 'block');
        }
    }
    //$('#delimiter'+id).html('<img src="/img/submenu_delimiter_ac.gif" width="2" height="12" alt="" />');

    //$('#delimiter'+id).html('<img src="/img/p.gif" width="2" height="12" alt="" />');
    $('#delimiter'+id).css('visibility', 'hidden');

    intro.lastShowedSubmenuId = id;
}

// PORTFOLIO -----------------------------------------------------------
var portfolio = {};

portfolio.init = function() {

  $('.cottage_portfolio').hover(
      function () {
        $('#photo-bg').stop();
        $('#photo-bg').animate({width: "0px", height: "0px", bottom: "0px"}, 1000);
        $('#photo-indicator').css('background', '#9bcf15');
      }, 
      function () {
        $('#photo-bg').stop();        
        $('#photo-bg').animate({width: "245px", height: "330px", bottom: "352px"}, 1000);
        $('#photo-indicator').css('background', '#1696d1');
      }
    );

  $('.cottage_portfolio').click(
      function () {
        window.location.href = $('#photo-link').attr('href');        
      }
  );

  $('.folder_photo').hover(
      function () {
        var idx = $(this).attr('id').substring(6);
        $('#photo-bg-'+idx).stop();        
        $('#photo-bg-'+idx).animate({width: "0px", height: "0px", bottom: "0px"}, 1000);
        $('#photo-indicator-'+idx).css('background', '#9bcf15');
      }, 
      function () {
        var idx = $(this).attr('id').substring(6);
        $('#photo-bg-'+idx).stop();        
        $('#photo-bg-'+idx).animate({width: "250px", height: "210px", bottom: "231px"}, 1000);
        $('#photo-indicator-'+idx).css('background', '#1696d1');
      }
    );

  $('.folder_photo').click(
      function () {
        var idx = $(this).attr('id').substring(6);
        window.location.href = $('#photo-link-'+idx).attr('href');        
      }
  );
}

// GALLERY ---------------------------------------------------------------
var gallery = {};

gallery.init = function() {
    gallery.photoLoader = document.createElement('img');
    gallery.photoLoader.onload=function() {
        //$('#photo').stop();
        $('#photo').hide();
        $('#photo').html('<img src="/photos/'+gallery.photo.fname+'" width="'+gallery.photo.width+'" height="'+gallery.photo.height+'" alt="" />');
        $('.footer_gallery_nav_title').text(gallery.photo.title);
        $('#photo').fadeIn(500);
    }
    $('.btn_show_photo').click(function () { gallery.showPhoto(this);});
}

gallery.showPhoto = function(elem) {
    $(elem).css('background', '#9bcf15');
    $('#photo').fadeOut(500, function() {
                                gallery.photo = photos[$(elem).attr('id')];
                                $('#photo').html('<div class="img_preloader"></div>');
                                $('#photo').show();
                                $(gallery.photoLoader).attr('src', '/photos/'+gallery.photo.fname);
                             });
}

/*gallery.init = function() {
    gallery.photoLoader = document.createElement('img');
    gallery.photoLoader.onload=function() {
        $('#photo').stop();
        gallery.photoIsLoaded = true;
        //$('#photo').hide();
        $('#photo').html('<img src="/photos/'+gallery.photo.fname+'" width="'+gallery.photo.width+'" height="'+gallery.photo.height+'" alt="" />');
        alert('<img src="/photos/'+gallery.photo.fname+'" width="'+gallery.photo.width+'" height="'+gallery.photo.height+'" alt="" />');
        $('.footer_gallery_nav_title').text(gallery.photo.title);
        $('#photo').fadeIn(500);
    }
    $('.btn_show_photo').click(function () { gallery.showPhoto(this);});
}

gallery.showPhoto = function(elem) {
    $(elem).css('background', '#9bcf15');
    $('#photo').fadeOut(500, function() {
                                gallery.photo = photos[$(elem).attr('id')];
                                gallery.photoIsLoaded = false;
                                $(gallery.photoLoader).attr('src', '/photos/'+gallery.photo.fname);

                                 $('#photo').show();
                                 $('#photo').html('<div class="img_preloader"></div>');
                             });
    //$('#photo').show();
    //$('#photo').html('<div class="img_preloader"></div>');

    //gallery.photo = photos[$(elem).attr('id')];
    //gallery.photoIsLoaded = false;
    //$(gallery.photoLoader).attr('src', '/photos/'+gallery.photo.fname);
}*/

// NEWS -----------------------------------------------------------
var news = {};

news.init = function() {


  $('.folder_photo').hover(
      function () {
        var idx = $(this).attr('id').substring(6);
        $('#photo-indicator-'+idx).css('background', '#9bcf15');
      }, 
      function () {
        var idx = $(this).attr('id').substring(6);
        $('#photo-indicator-'+idx).css('background', '#1696d1');
      }
    );

  $('.folder_photo').click(
      function () {
        var idx = $(this).attr('id').substring(6);
        window.location.href = $('#photo-link-'+idx).attr('href');        
      }
  );

  $('.pop').click(
      function() {
        var pn = $(this).attr('id').substring(5);
        window.location.href = '/news/'+news.folderName+'/'+pn+'/';
      }
  );
}

