$(function() {
	$('.fadeThis').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this);
     if ($.browser.msie && $.browser.version < 9)
        $span.hide();
     else
        $span.css('opacity', 0);
	  $(this).hover(function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.show();
	    else
   	    $span.stop().fadeTo(500, 1);
	  }, function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.hide();
	    else
  	      $span.stop().fadeTo(500, 0);
	  });
	});
});

$(function() {
	$('.button-h').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this);
     if ($.browser.msie && $.browser.version < 9)
        $span.hide();
     else
        $span.css('opacity', 0);
	  $(this).hover(function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.show();
	    else
   	    $span.stop().fadeTo(500, 1);
	  }, function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.hide();
	    else
  	      $span.stop().fadeTo(500, 0);
	  });
	});
});

$(function() {
	$('.img-holder:not(.n-s)').append('<div></div>').each(function () {
	  var $span = $('> div', this);
     if ($.browser.msie && $.browser.version < 9)
        $span.hide();
     else
        $span.css('opacity', 0);
	  $(this).hover(function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.show();
	    else
   	    $span.stop().fadeTo(500, 1);
	  }, function () {
	    if ($.browser.msie && $.browser.version < 9)
	      $span.hide();
	    else
  	      $span.stop().fadeTo(500, 0);
	  });
	});
});


// menu

var menu_timeout_open = false;
var menu_timeout_close = false;

$(function () {

   var menu_speed_show = 300;
   var menu_show_timeout = 300;

   $("#nav li").each(function () {
      var sub_ul = $(this).children("div");
      
      if (!sub_ul.length)
      {
         $(this).hover(function () {
            if (menu_timeout_open)
               clearTimeout(menu_timeout_open);
         },
         function () {
         });
         return;
      }
      
      prev_left = 190;
      
      var new_left = parseInt( prev_left ) - 10;
      var init_left = new_left+20;

      if ($.browser.msie && $.browser.version < 9)
      {
         sub_ul.css({
            display: 'none'
         });
      }
      else
      {
         sub_ul.css({
            display: 'none',
            opacity: 0,
         });
      }
      
      $(this).hover(function () {
         if (menu_timeout_open)
            clearTimeout(menu_timeout_open);
         
         menu_timeout_open = setTimeout(function () {
            sub_ul.find("div").hide();
            if ($.browser.msie && $.browser.version < 9)
            {
               sub_ul.show();
            }
            else
            {
               sub_ul.css({
                  display: 'block',
                  opacity: 0,
                  left: init_left
               }).animate({
                  opacity: 1,
                  left: new_left
               }, {
                  duration: menu_speed_show,
                  queue: false,
                  complete: function () {
                     if ($.browser.msie && $.browser.version < 9) this.style.removeAttribute('filter');
                  }
               });
            }
         }, menu_show_timeout);
      },
      function () {
         sub_ul.hide();
      });
   });
   
   $("#nav").hover(function () { },function () {
      //$("#nav div").hide();
      if (menu_timeout_open)
         clearTimeout(menu_timeout_open);
   });
   
   $("#nav div").each(function () {
      var tout_hide = false;
      var d = $(this);
      d.hover(function () {
         if (tout_hide)
            clearTimeout(tout_hide);
      },
      function () {
         tout_hide = setTimeout(function () {
            d.hide();
         }, 500);
      });
   });

});

// end menu


// flickr animations
$(function () {
   $(".flickr").parent().hover(function () {
   },
   function () {
      $(".flickr i").animate({
         opacity: 0
      }, {
         duration: 300,



         queue: false
      });
   });
   $(".flickr i").hover(function () {
      $(this).animate({
         opacity: 0

      }, {
         duration: 300,
         queue: false
      });      
      $(".flickr i").not( $(this) ).animate({
         opacity: 0.4
      }, {
         duration: 300,
         queue: false
      });
   }, function () {
      
   });
});
// end flickr animations

// go up arrow
$(function () {
   $(".go_up").click(function () {
      $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: 0}, 500);
      return false;
   });
});
// end go up arrow

// form validation
function update_form_validation() {
   $("[placeholder]").each(function () {
      $(this).val( $(this).val().replace( $(this).attr("placeholder"), '' ) );
      $(this).unbind().placeholder();
   });
   $("form .go_button, form .do_add_comment").unbind().click(function () {
   
      $(this).parents("form").find("input, textarea").each(function () {
         $(this).val( $(this).val().replace( $(this).attr("placeholder"), '' ) ).unbind().placeholder();
      });
      $(".formError").remove();
      
      var e=$(this).parents("form");
      e.find("input, textarea").each(function () {
         $(this).unbind();
         $(this).val( $(this).val().replace( $(this).attr("placeholder"), "" ) );
      });
      if (!e.attr("valed"))
      {
         if ( e.hasClass("ajaxing") )
         {
            e.validationEngine({
               ajaxSubmit: true,
               ajaxSubmitFile: e.attr("action")
            });
         }
         else
         {
            e.validationEngine();
         }
      }
      e.attr("valed", "1");
      e.submit(); 
      e.find("input, textarea").each(function () {
         $(this).placeholder();
      });      
      return false;
   });
   $("form .do_clear").unbind().click(function (e) {
      $(this).parents("form").find("input, textarea").each(function () {
         $(this).val("").unbind().placeholder();
      });
      $(".formError").remove();
      
      if ($(this).attr("remove") && !$(this).parents("#form_prev_holder").length) 
      {
         move_form_to( $("#form_prev_holder") );
         $("#form_holder .do_clear").removeAttr('remove');
      }
      
      return false;
   });
}
$(update_form_validation);
// end form validation

// comments form
function move_form_to(ee)
{
      var e = $("#form_holder").html();
      var tt = $("#form_holder .header").text();
      
      var sb =$("#form_holder .go_button").attr("title");
      
      var to_slide_up = ($(".comment_bg #form_holder").length ? $("#form_holder") : $(".share_com"));
      
      to_slide_up.slideUp(500, function () {
         $("#form_holder").remove();
         
         ee.append('<div id="form_holder">'+e+'</div>');
         $("#form_holder .header").html(tt);
         $("#form_holder [valed]").removeAttr('valed');
         $("#form_holder .do_clear").attr('remove', 1);
         
         $("#form_holder .go_button cufon").remove();
         $("#form_holder .go_button span span :not(i)").remove();
         $("#form_holder .go_button span i").after( sb );
         
         //alert(sb);
         
         Cufon('#form_holder .header', {
            color: '-linear-gradient(#0a0a0a, #444444)'
         });
         
         Cufon('a.button.big', {
           color: '-linear-gradient(#c4c4c4, 0.4=#f9f9f9, #f9f9f9)',textShadow: '1px 1px #000'
         });
         
         $(".formError").remove();
         
         $("#form_holder").hide();
         
         to_slide_up = ($(".comment_bg #form_holder").length ? $("#form_holder") : $(".share_com"));
         if (to_slide_up.hasClass('share_com')) $("#form_holder").show();
         
         to_slide_up.slideDown(500);
         
         if (ee.attr("id") != "form_prev_holder")
         {
            var eid = ee.parent().attr("id");
            if (!eid)
               eid = "";
            $("#comment_parent").val( eid.replace('comment-', '') );
         }
         else
         {
            $("#comment_parent").val("0");
         }
         
         update_form_validation();
      });
}
$(function () {
   $(".comment .comments").click(function () {
      move_form_to( $(this).parent().parent().parent() );
      return false;
   });
});
// end comments form

// albums

var folio_caption_fade_speed = 300;
var folio_mask_fade_slidedown_speed = 300;
var folio_desc_fade_speed = 300;

var folio_photos_bg_fade_speed = 1000;
var folio_photos_gal_fade_speed = 500;

var prev_scroll_top = 0;

function update_photos_events()
{
   if (menu_timeout_open)
      clearTimeout(menu_timeout_open);


   $("#nav div").hide();

   $(".big_gallery", current_album).show().css('visibility', 'hidden');
	if (1) $('.multipics', current_album).masonry({
	    columnWidth: 240, 
    	 itemSelector: '.go_pic',
	    animate: false
	});
	$(".big_gallery", current_album).css('visibility', 'visible').hide();
	
	if ( $.browser.opera || $.browser.msie && $.browser.version < 8 ) {
			$('#bg').css({
			'display': 'none'
		});
	}
	
   Cufon('.big_gallery h1', {
      fontWeight: 'bold',
      color: '-linear-gradient(#f5f2eb, 0.3=#f5f2eb, #a6a39d)', textShadow: '0 -2px #000'
   }); 
   Cufon('.go_back', {
      fontWeight: 'bold',
      color: '-linear-gradient(#473e2b, 0.4=#473e2b, #1c1a19)', textShadow: '0 1px #fff'
   });
  
   $(".big_gallery .go_back").unbind().click(function () {
     //$(window).scrollTop(prev_scroll_top);
     
      if ($.browser.opera)
         $(document).unbind('mousewheel');
     
     
     $(".big_gallery").fadeOut(folio_photos_gal_fade_speed, function () {
        $(".big_gallery_bg").fadeOut(folio_photos_bg_fade_speed, function () {
            $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: prev_scroll_top}, 500, function () {
               $('#bg').css({
                  'height': 'auto',
                  'overflow': 'visible'
               });
               if ( $.browser.opera || $.browser.msie && $.browser.version < 8 ) {
                     $('#bg').css({
                     'display': 'block'
                  });
               }
            });
        });
     });
     return false;
   });
   
   if (!$.browser.msie)
   {
      
      $(".multipics a i").css({
         display: 'block',
         opacity: 0
      });
      
      $(".multipics a").hover(function () {
         $("i", this).animate({
            opacity: 1
         }, {
            duration: 500,
            queue: false
         });
      },
      function () {
         $("i", this).animate({
            opacity: 0
         }, {
            duration: 500,
            queue: false
         });
      });
   }
   	
   $(".go_pic").each(function () {
      $(this).attr("rel", "gal[g]").attr("title",  "");
   });
   $("a[rel=gal\\[g\\]]").prettyPhoto({
      theme: 'light_rounded'
   });
	
}

var current_album = false;

$(function () {
   if ( !$(".folio").length ) return;
   
   $(".folio").each(function () {
      var box = $(this);
   
      box.click(function () {
      
         var cl = box.parent().attr("class").replace(/^.*for_(post_[0-9]+).*$/, '$1');
         current_album = $("." + cl);
         
         if (!current_album.length)
            alert("Album not found (."+cl+")");
      
         prev_scroll_top = $(window).scrollTop();
      
         $(".big_gallery", current_album).hide();
         
         $(".big_gallery_bg", current_album).css({
            display: 'block',
            opacity: 1,
            visibility: 'visible',
            'height': $("#bg").height()+"px",
            'min-height': $(window).height()+"px",
      	   //top: $(window).scrollTop()+"px"
      	   top: 0
         }).hide().fadeIn(folio_photos_bg_fade_speed, function () {
            //$(window).scrollTop(0);
            //$(".big_gallery_bg").css('top', 0);
            update_photos_events();
            $("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: 0}, 500, function () {
               //$(".big_gallery_bg", current_album).height( $("#bg").height() );
               
               var hh =  $(".big_gallery", current_album).height() + 118;
               if ( hh < $(window).height() )
                  hh = $(window).height();
               
               $("#bg, .big_gallery_bg").css({
                  height: hh+"px",
                  overflow: 'hidden'
               });
            });
            //$("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).css({scrollTop: 0});
            //$(".big_gallery_bg", current_album).height( $(".big_gallery", current_album).height() + 80 );
            $(".big_gallery", current_album).hide().fadeIn(folio_photos_gal_fade_speed);
         });
         return false;
      });
      
      box.hover(function () {
         if ($.browser.msie)
         {
            $(".folio_just_caption", box).css({
               visibility: 'hidden'
            });
            $(".folio_mask", box).css({
               display: 'block',
               height: '100%'
            });
         }
         else
         {
            $(".folio_just_caption", box).animate({
               opacity: 0
            }, {
               queue: false,
               duration: folio_caption_fade_speed
            });
            var to_height = $(".folio_mask", box).css('height', '100%').height();
            $(".folio_mask .folio_desc", box).hide();
            $(".folio_mask", box).css({
               display: 'block',
               height: 0,
               opacity: 0
            }).animate({
               height: to_height,
               opacity: 1
            }, {
               queue: false,
               duration: folio_mask_fade_slidedown_speed,
               complete: function () {
                  $(".folio_desc", box).css({
                     display: 'block',
                     opacity: 0
                  }).animate({
                     opacity: 1
                  }, {
                     queue: false,
                     duration: folio_desc_fade_speed,
                     complete: function () {
                        if ($.browser.msie) this.style.removeAttribute('filter');
                     }
                  });
               }
            });
         }
      }, function () {
         if ($.browser.msie)
         {
            $(".folio_just_caption", box).css({
               visibility: 'visible'
            });
            $(".folio_mask", box).css({
               display: 'none',
               height: '100%'
            });
         }
         else
         {
            $(".folio_mask", box).animate({
               height: 0,
               opacity: 0
            }, {
               queue: false,
               duration: folio_mask_fade_slidedown_speed
            });
            $(".folio_just_caption", box).animate({
               opacity: 1
            }, {
               queue: false,
               duration: folio_caption_fade_speed
            });
         }
      });
   });
});
// end albums

// PIE
$(function () {
    $('.folio, .folio_mask, .folio_caption, .folio_just_caption').each(function() {
        if ($.browser.msie) PIE.attach(this);
    });
});
// end PIE

// for test
$(function () {
   //$(".folio:first").click();
});

// form-search
$(function () {
	$('.int').focus(function () {
		$(this).parent().addClass('i-f');}).blur(function () {
			$(this).parent().removeClass('i-f')
		});
});

$(function () {
   
   $(".filters").each(function () {
      var holder = $(this);
      $(this).find(".filter").click(function () {
      
         holder.find(".act").removeClass("act");
         $(this).addClass("act");
      
         Cufon('a.button.big', {
           color: '-linear-gradient(#c4c4c4, 0.4=#f9f9f9, #f9f9f9)',textShadow: '1px 1px #000'
         });
         Cufon('a.button.big.act', {
           color: '-linear-gradient(#4d4d4d, #797979)',textShadow: '1px 1px #000'
         });
      
         var cl = $(this).attr('class');
         cl = cl.replace(/^.*filter_([^ ]+).*$/, '$1');
         var iso = $(".isotoped");
         if (!iso.length)
         {
            alert("No posts to filter.");
            return false;
         }
         
         var f = '.item_'+cl;
         if ( cl == 'all' )
            f = '*';
         iso.isotope({
            filter: f
         });
         return false;
      });
   });
   
});



/* Define iOS devices */
jQuery.extend(jQuery.browser,
	{SafariMobile : navigator.userAgent.toLowerCase().match(/iP(hone|ad)/i) }
);

// form-search
$(function () {
	$('.int').focus(function () {
		$(this).parent().addClass('i-f');}).blur(function () {
			$(this).parent().removeClass('i-f')
		});
});

/* Hide hampage overlay mast for iOS device */
$(function() {
	if ($.browser.SafariMobile){
		$("#big-mask").css("display", "none");
	}
});

//footer
/*$(function () {
	$(window).resize(function () {
		h = $(window).height() - $("#top_bg").height() - $("#content").height();
		$("#content").css('min-height', h+"px");
	});
	$(window).trigger("resize");
});*/

/* Create masonry layout with Isotope (http://isotope.metafizzy.co/) */

// Masonry for regular POSTS
$(function(){
	var $multicol = $('#multicol');
	if (!$multicol.length)
		return;
	$multicol.addClass('isotoped');
	$multicol.isotope({
		itemSelector : '#multicol .article_box',
		transformsEnabled: false,
		animationEngine: 'jquery',
		masonry : {
			columnWidth : 280
		},
		animationOptions: {
			duration: 750,
			easing: 'linear',
			queue: false
		}
	});
});

// Masonry for PHOTOS and ALBUMS
$(function(){
	var $multicol = $('#multicol-gal');
	if (!$multicol.length)
		return;
	$multicol.addClass('isotoped');
	$multicol.isotope({
		itemSelector : '#multicol-gal .gallery-box',
		transformsEnabled: false,
		masonry : {
			columnWidth : 280
		},
		animationOptions: {
			duration: 750,
			easing: 'linear',
			queue: false
		}
	});

});


/* Swap featured image by vector objects of slashed shape */
$(document).ready(function() {

	//Add rollovers to post featured image
	$('.img-holder').append('<span class="zoom"></span>').each(function () {
		var $span = $('> span.zoom', this);
		if ($.browser.msie && $.browser.version < 9)
			$span.hide();
		else
			$span.css('opacity', 0);
		$(this).hover(function () {
			if ($.browser.msie && $.browser.version < 9)
				$span.show();
			else
				$span.stop().fadeTo(1000, 1);
		}, function () {
			if ($.browser.msie && $.browser.version < 9)
				$span.hide();
			else
				$span.stop().fadeTo(1000, 0);
		});
	});

	// Swap featured images with vector objects
	$(".img-holder").each(function () {
		var img = $(this).find("img");
		var img_w = img.attr("width");
		var img_h = img.attr("height");
		var img_h_m = img_h - 30;
		var img_src = img.attr("src");
		img.css('display' , 'none');

		var paper = Raphael(this, img_w, img_h);
		// iOS devices can not apply path background image correctly. We are using clipping instead.
		if ($.browser.SafariMobile){
			var p = "M0,30L"+img_w+",0L"+img_w+","+img_h_m+"L0,"+img_h+"L0,30";
			var p_img = paper.image(img_src, 0, 0, img_w, img_h);
			p_img.attr({
				stroke: "none",
				"clip-rect": p
			});
		}
		else{
			var c = paper.path("M 0 30   L "+img_w+" 0   L "+img_w+" "+img_h_m+"   L 0 "+img_h+"   L 0 30");
			c.attr({
				stroke: "none",
				fill: "url("+img_src+")"
			});
		}
	});

	// Add rollovers to gallery thumbnails
	$(".img-holder"+($.browser.msie ? ":not(.n-s)" : "")+" div").each(function () { 
		var img_w = $(this).parent("div").width();
		if ($.browser.msie)
	        var img_h = $(this).parent("div").height() + 1;
		else
			var img_h = $(this).parent("div").height() + 2;
		var img_h_m = img_h - 30;

		var paper = Raphael(this, img_w, img_h);
		var c = paper.path("M 0 30   L "+img_w+" 0   L "+img_w+" "+img_h_m+"   L 0 "+img_h+"   L 0 30");
		c.attr({
			stroke: "none",
			fill: "url(images/gal-h.png)"
		});
	});

	// Swap HomePage thumbnails with vector objects
/*	$(".slide-h").each(function () {
		var img_w = $(this).find("img").attr("width");
		var img_h = $(this).find("img").attr("height");
		var img_h_m = img_h - 15;
		var img_src = $(this).find("img").attr("src");

		var paper = Raphael(this, img_w, img_h);

		if ($.browser.SafariMobile){
			var p = "M0,15L"+img_w+",0L"+img_w+","+img_h_m+"L0,"+img_h+"L0,15";
			var img = paper.image(img_src, 0, 0, img_w, img_h);
			img.attr({
				stroke: "none",
				"clip-rect": p
			});
		}
		else{
			var c = paper.path("M 0 15   L "+img_w+" 0   L "+img_w+" "+img_h_m+"   L 0 "+img_h+"   L 0 15");
			c.attr({
				stroke: "none",
				fill: "url("+img_src+")"
			});
		}
	});*/
});


/* Service tooltips: tags, categories, social links, etc. */
$(function() {
	$('.ico-l').each(function () {
		var $tip = $('> .info-block', this);
		var $span = $('> span', this);
		if (!$span.length) {
			var $span = $('> a', this);
		};
		var $old_html = $tip.html();
		var $new_html = '<div class="box-i-l"><div class="box-i-r"><span class="box-i">' + $tip.html() + '</span></div></div>';
		$(this).hover(function () {
			$span.addClass('act');
			$tip.html($new_html);			
			if ($.browser.msie && $.browser.version < 9) {
				$tip.show();
			} else {
				$tip.css('display', 'none');
				$tip.stop().fadeTo(300, 1);}
		}, function () {
			$span.removeClass('act');
			if ($.browser.msie && $.browser.version < 9) {
				$tip.hide();
				$tip.html($old_html);
			} else {
				$tip.css('display', 'block');
				$tip.stop().fadeTo(50, 0, function() {$tip.css('display', 'none'); $tip.html($old_html);});
			}
		});
	});
});



/* New gallery */
$(function () {

   // normal hs
   $(".fadeThis").each(function () {
      if ( $(this).attr("href") == '#' )
         $(this).attr("href", $(this).find("img").attr("src") );
      this.onclick = function () {
         hs.expand(this, hs_config2)
         return false;
      };
   });

   // gallery 1 level 
   $(".one_level_gal").each(function () {
      els = $(".img-holder", this);
      els.each(function () {
         var config = {};
         $.extend(config, hs_config1);
         var im = $(this).children("img");
         var s = im.attr("src");
         //config.src = s;
         config.slideshowGroup = slideshow_options.slideshowGroup;
         var mini = $(this).children("a");
         if ( mini.length )
         {
            //config.src = mini.attr("href");
         }
         else
         {
            mini = $("<a />");
            mini.attr("href", s);
            mini.appendTo( $(this) );
         }
         
         mini.append( im.clone() );
         
         mini[0].onclick = function () {      
            return hs.expand(this, config);
         };
         
         $(this).click(function () {
            mini.trigger("onclick");
            return false;
         });
      });
   });
   
});




//jQuery.noConflict();
jQuery(document).ready(function($){
	
/* Quick Isotope for Gallery */
function do_isotope(iContainer, iItem, iWidth) {
	var $iContainer = $(iContainer);
	if (!iContainer.length)
		return;
	$iContainer.isotope({
		containerClass : 'isotoped',
		itemSelector : iItem,
		transformsEnabled: false,
		masonry : {
			columnWidth : iWidth
		},
		animationOptions: {
			duration: 750,
			easing: 'linear',
			queue: false
		}
	});
	//console.log(iContainer +' isotoped');
}
/*--------------------------------------------------*/

/*  Slasher for Gallery  */
function do_slash(iItem) {
	// Swap featured images with vector objects
	$(iItem).each(function () {
		var img = $(this).find("img");
		var img_w = img.attr("width");
		var img_h = img.attr("height");
		var img_h_m = img_h - 30;
		var img_src = img.attr("src");
		
		$(this).css('height',img_h);
		$(this).css('widtht',img_w);
		img.css('display' , 'none');

		var paper = Raphael(this, img_w, img_h);
		// iOS devices can not apply path background image correctly. We are using clipping instead.
		if ($.browser.SafariMobile){
			var p = "M0,30L"+img_w+",0L"+img_w+","+img_h_m+"L0,"+img_h+"L0,30";
			var p_img = paper.image(img_src, 0, 0, img_w, img_h);
			p_img.attr({
				stroke: "none",
				"clip-rect": p
			});
		}
		else{
			var c = paper.path("M 0 30   L "+img_w+" 0   L "+img_w+" "+img_h_m+"   L 0 "+img_h+"   L 0 30");
			c.attr({
				stroke: "none",
				fill: "url("+img_src+")"
			});
		}
	});
}
/*--------------------------------------------------*/

/* Overlay for gallery */
function build_overlay (iItem) {
	// Add rollovers to gallery thumbnails
	$(iItem).each(function () { 
		var img_w = $(this).parent('div').width();
		if ($.browser.msie)
			var img_h = $(this).parent('div').height() + 1;
		else
			var img_h = $(this).parent('div').height() + 2;
		var img_h_m = img_h - 30;

		var paper = Raphael(this, img_w, img_h);
		var c = paper.path("M 0 30   L "+img_w+" 0   L "+img_w+" "+img_h_m+"   L 0 "+img_h+"   L 0 30");
		c.attr({
			stroke: "none",
			fill: "url(images/gal-h.png)"
		});
	});
	$(iItem).append('<span class="zoom"></span>').each(function () {
		var $span = $(this);
		if ($.browser.msie && $.browser.version < 9)
			$span.hide();
		else
			$span.css('opacity', 0);
		$(this).parent('div').hover(function () {
			if ($.browser.msie && $.browser.version < 9)
				$span.show();
			else
				$span.stop().fadeTo(300, 1);
		}, function () {
			if ($.browser.msie && $.browser.version < 9)
				$span.hide();
			else
				$span.stop().fadeTo(300, 0);
		});
	});
}
/*--------------------------------------------------*/

/* zGallery */
var in_work = 0;
$('.two_level_gal .img-holder').click(function() {
	
	if (in_work > 0){
		return false;
	}
		
	in_work = 1;
	
	var cl = $(this).parents(".gallery-box").attr("class").replace(/^.*link_(gal[0-9]+).*$/, 'for_$1');
	var photos = $('.' + cl).clone();

	if (!photos.length){
		alert('Error. Album "'+cl+'" is empty.');
		in_work = 0;
		return false;
	}

	var h2 = photos.children('strong').detach().html();
	var old_html = photos.html();

	photos.find("a").each(function() {
		var href = $(this).attr('href');
		var src = $(this).attr('data-src');
		var width = $(this).attr('data-width');
		var height = $(this).attr('data-height');
		var caption = $(this).text();

		var new_html = '<div class="gallery-box"><div class="overlay"><a href="'+ href +'" title="'+ caption +'"><img src="'+ src +'" width="'+ width +'" height="'+ height +'" alt="" /></a></div></div>';

		$(this).replaceWith(new_html);
	});
		
	var new_html = '<div class="holder"><a class="button" href="#"><span class="but-r"><i class="back"></i>BACK</span></a><h2 class="cufon_me">' + h2 + '</h2><div class="multicol-gallery">' + photos.html() + '</div><div class="but-bottom"><a class="button bot" href="#"><span class="but-r"><i class="back"></i>BACK</span></a></div></div>';

	var gallery = $('<div class="bg '+ cl +'" />');
	gallery.html(new_html).appendTo('body').addClass('hidden').addClass('gal-full');
	
	Cufon.refresh(); //undefined selector. this may slow down site.
	do_slash('.bg .gallery-box');
	build_overlay('.bg .gallery-box .overlay');
	var elems = gallery.find(".gallery-box");

	elems.each(function () {
		$(this).addClass("hs_attached");
		var link = $(this).find('a');

		link[0].onclick = function () {
			return hs.expand(this, slideshow_albums);
		};

		$(this).click(function () {
			$(link).trigger("onclick");
			return false;
		});
	});

	var prev_scroll_top = $(window).scrollTop();
	
	$('html:not(:animated)'+( ! $.browser.opera ? ',body:not(:animated)' : '')).animate({scrollTop: 0}, 500, function () {

		$(".holder", gallery).css({
			visibility: 'visible',
			opacity: 0,
			'z-index': 999
		});

		$('#bg').css({
			position: 'fixed',
			top: 0,
			width: '100%'
		});

		gallery.css({
			display: 'block',
			opacity: 0,
			visibility: 'visible'
		}).animate({
			opacity: 1
		}, {
			queue: false,
			duration: 1000,
			complete: function (){

				do_isotope('.bg .multicol-gallery' , '.bg .gallery-box', 260);

				$(".holder", gallery).animate({
					opacity: 1
				}, {
					queue: false,
					duration: 1000,
					complete: function () {
						$("a.button").unbind('click').click(function () {
							$("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: 0}, 500, '', function () {
								gallery.animate({
									opacity: 0
								}, {
									queue: false,
									duration: 500,
									complete: function () {
										$('.bg').remove();
										$('#bg').css({position: 'relative'});
										$("html:not(:animated)"+( ! $.browser.opera ? ",body:not(:animated)" : "")).animate({scrollTop: prev_scroll_top}, 500, '', function () {});										
									}
								});

							});

							in_work = 0;
							return false;
						});
					}
				});
			}
		});
	});
	return false;
});
/*--------------------------------------------------*/

});
