function image(n){
   $(".class-gallery .image-large").hide();
   $(".image"+n).show();
}

function popupImage(url){
   window.open(url, "image", "menubar=0,location=0,status=0,resizable=1,width=400,height=400");
}

function loadScrollbar(h){
   var full = $(".content-view-full:first");
   if(full.attr("scrollHeight") <= h) return false;

   full.wrapInner("<div id='scroll-content'></div>");
   var scrollContent = full.find("#scroll-content");
   scrollContent.css({ height: h+"px" });
   var slider = $("<div id='slider'></div>");
   full.css({ position:'relative'}).append(slider);
   slider.css({ height: h+"px" }).slider({
       axis: 'vertical',
       orientation: 'vertical',
       value: 100,
       change: function(e, ui){
	 var maxScroll = scrollContent.attr("scrollHeight") - scrollContent.height();
	 scrollContent.animate({scrollTop: (100-ui.value) * (maxScroll / 100) }, 1000);
       },
       slide: function(e, ui){
	 var maxScroll = scrollContent.attr("scrollHeight") - scrollContent.height();
	 scrollContent.attr({scrollTop: (100-ui.value) * (maxScroll / 100) });
       }
   });
}

var ie6offset;
function full(url, w, h, desc){
   ie6offset = (jQuery.browser.msie && jQuery.browser.version == "6.0") ? document.documentElement.scrollTop : 0;
   var lbg = $("<div class='lightbox-bg'></div>");
   lbg.css({height: '20px',
            top: ie6offset + document.documentElement.clientHeight/2,
            width: '20px',
            left: '50%'});
   $('body').append(lbg);

   lbg.click(function(){
      $(".lightbox-bg, .lightbox, .close").fadeOut(500, function(){ $(this).remove() });;
   });

   lbg.animate({width: '100%', left: '0'}, 400, function(){
   lbg.animate({height: document.documentElement.clientHeight,
                top: ie6offset,
                opacity: '0.8'}, 400, function(){

                   lbg.css({position: 'absolute', top: '0', height: document.documentElement.scrollHeight});

                   $('body').append("<div class='lightbox'><img class='lightbox-img' /></div>");
                   var img = $(".lightbox-img");
		   img.after("<div>"+decodeURIComponent(desc)+"</div>");
   		   var lb = $(".lightbox");
                   lb.css('display', 'none');
                   lb.css('left', (document.documentElement.clientWidth - w) / 2);
		   var height = lb.height() + h;
		   var relative_top = (document.documentElement.clientHeight - height) / 2;
		   if(relative_top < 20) relative_top = 20;
                   lb.css('top', document.documentElement.scrollTop + relative_top);
                   lb.css('width', w);
                   img.attr('src', url);
                   img.load(function(){
                      lb.fadeIn(500, function(){
                         lbg.css("height",document.documentElement.scrollHeight);
		      });
                   });
                   img.click(function(){
                      $(".lightbox-bg, .lightbox, .close").fadeOut(500, function(){ $(this).remove() });
                   });

		   var close = $("<div class='close' />");
		   close.css('left', (document.documentElement.clientWidth - w) / 2 + w - 12);
		   close.css('top', document.documentElement.scrollTop + relative_top - 12);
		   $('body').append(close);
                   close.click(function(){
                      $(".lightbox-bg, .lightbox, .close").fadeOut(500, function(){ $(this).remove() });;
		   });
                });
   });
}

/* SUBMENUS */
var topmenuitems = {};
var topsubmenuitems = {};
function loadMainSubMenu(type){
      $("#topmenu a").each(function(){
         var id = $(this).attr('node_id');
         var submenu = $("#submenu"+id);
	 if(type==1){
            submenu.css('left',$("#topmenu").position().left + $(this).position().left);
	 } else if(type==2){
            submenu.css('left',$("#topmenu").position().left);
	 }
         submenu.css('top',$("#topmenu").attr('offsetTop') + $(this).attr('offsetTop') + $(this).outerHeight());
      });
      $("#topmenu a").bind("mouseover", function(){
         var id = $(this).attr('node_id');
         var submenu = $("#submenu"+id);
         topmenuitems[id] = true;
         if(!topsubmenuitems[id]){
            submenu.slideDown(50);
         }
      });
      $("#topmenu a").bind("mouseout", function(){
         var id = $(this).attr('node_id');
         var submenu = $("#submenu"+$(this).attr('node_id'));
         topmenuitems[id] = false;
         setTimeout(function(){
            if(!topsubmenuitems[id]) submenu.slideUp(100);
         }, 10);
      });
      $(".topsubmenu").bind("mouseenter", function(){
         var id = $(this).attr('node_id');
         topsubmenuitems[id] = true;
      });
      $(".topsubmenu").bind("mouseleave", function(){
         var id = $(this).attr('node_id');
         topsubmenuitems[id] = false;
         var that = this;
         setTimeout(function(){
           if(!topmenuitems[id]) $(that).slideUp(50);
         }, 10);
      });
}

$(document).ready(function(){
   $("div.folder-type3 div.content-view-children div.attribute-title a").mouseover(function(){
      $("div.folder-type3 div.content-view-children div.attribute-image").hide();
      $(this).parent().next().show();
   });
   $("div.folder-type3 div.content-view-children div.attribute-title a:first").trigger('mouseover');

   $("div.folder-type4").each(function(){
      var ul = $("<ul class='tabs'></ul>");
      var that = this;
      var maxheight = 0;
      $(this).children('.content-view-children').children('.content-view-full').each(function(){
         if(maxheight < $(this).height() ) maxheight = $(this).height();
         var li = $("<li></li>");
         var that2 = this;
         li.html($(this).prev().html());
	 $(this).prev().remove();
	 $(this).find('h1').remove();
         li.click(function(){
            ul.children().removeClass('selected');
            $(this).addClass('selected');
            $(that).children('.content-view-children').children('.content-view-full').hide();
            $(that2).show();
         });
         ul.append(li);
      });
//      $(this).find('div.content-view-full').height(maxheight);
      $(this).children('.content-view-children').prepend(ul);
      ul.find('li:first').trigger('click');
   });

   $("div.gallery-type5").galleryslide();

});

