$.widget('ui.gallery', {
	_create: function(){
		var obj = this;
		var parent = this.element;
		this.mouseTimer = null;
		this.thumbsVisible = true;
		this.thumbs = parent.find('.thumb-container .thumbs');

		var itemWidth = 107;
		this.count = parent.find('.thumbs').children('.thumb').length;
		
		parent.find('.active-image img').live('click',function(){
			if(!obj.thumbs.hasClass('scrolling')){
				var ind = obj.thumbs.children('.thumb').index(obj.thumbs.children('.thumb.active')) + 1;
				if(ind < obj.count){
					if((!$('.fullscreen-gallery').is(':visible') && ind % 6 == 0) || ($('.fullscreen-gallery').is(':visible') && ind % 17 == 0)){
						var mleft = parseInt(obj.thumbs.css('margin-left'))-642;
						
						if(!obj.thumbs.hasClass('scrolling')){
							obj.thumbs.addClass('scrolling');
							obj.thumbs.animate({'margin-left': mleft+'px'},1000,function(){
								obj.thumbs.removeClass('scrolling');
							});
							listItem = parent.find('.large-pagination').children('.pager.active');
							var active_index = parent.find('.large-pagination').children(' .pager').index(listItem);
							active_index+=1;
							parent.find('.large-pagination').children('.pager.active').removeClass('active');
							parent.find('.large-pagination').children('.pager:eq('+active_index+')').addClass('active');
						}
					}
					var thumb = parent.find('.thumb-container .thumbs').children('.thumb:eq('+ind+')');
					var thumb_margin = parseInt(parent.find('.thumb-container .thumbs').css('margin-left'))*-1;
					if( ((ind+1)*110)-thumb_margin > $(document).width()){
						parent.find('.thumb-infinite .next-side').click();
					}
					thumb.click();
				}else{
					parent.find('.thumb-infinite .thumbs').animate({'margin-left': '0px'},1000);
					parent.find('.thumb-container .thumbs').children('.thumb:first').click();
					parent.find('.large-pagination').children('.pager:first').click();
				}
			}
		});

		parent.find('.active-image').mouseenter(function(){
			if($(this).find('.description').html().length > 0 && !$(this).hasClass('mouseover')){
				$(this).addClass('mouseover');
				var desc = $(this).find('.desc-block');

				desc.css({ visibility:'hidden', height:'auto', display:'block' });
				var height = desc.height();
				var width = desc.width() / 2;
				if($('.fullscreen-gallery').is(':visible')){
					desc.css({ visibility:'visible', height:'auto', display:'block' });
					desc.css({ marginLeft: '-'+width+'px' });
					desc.css({ marginTop: '-'+height+'px' });
					desc.stop(true,false).animate({ marginTop:'0px' }, 1000);
				}else{
					desc.css({ visibility:'visible', height:'0px', display:'block' });
					desc.stop(true,false).animate({ height:height }, 500);
				}
			}
			var fullscreen = $(this).find('.full-screen');
			fullscreen.stop(true,false).animate({ opacity:'0.6' }, 500);
		});
		parent.find('.active-image').mouseleave(function(){
			var desc = $(this).find('.desc-block');
			var height = $(this).find('.desc-block').height();

			if($('.fullscreen-gallery').is(':visible')){
				desc.stop(true,false).animate({ height:'0px', marginTop:'0px' }, 700);
			}else{
				desc.stop(true,false).animate({ height:'0px' }, 500);
			}
			$(this).removeClass('mouseover');
			var fullscreen = $(this).find('.full-screen');
			fullscreen.stop(true,false).animate({ opacity:'0' }, 500);
		});
		parent.find('.active-image').mousemove(function(){
			if (obj.mouseTimer) {
		    	window.clearTimeout(obj.mouseTimer);
		    }
			if (!obj.thumbsVisible) {
	        	obj.showThumbs();
	    	}
		    obj.mouseTimer = window.setTimeout(function(){ obj.hideThumbs(); }, 2500);
		});
		parent.find('.thumb-container').mouseenter(function(){
			window.clearTimeout(obj.mouseTimer);
			if (!obj.thumbsVisible) {
	        	obj.showThumbs();
	    	}
		});

	},

	_init: function() {
		var obj = this;
		var parent = this.element;
		this.thumbs = parent.find('.thumb-container .thumbs');

		var itemWidth = 107;
		this.count = parent.find('.thumbs').children('.thumb').length;

		parent.find('.thumb-container .totals .total').html(this.count);
		

		parent.find('.thumbs .thumb .overlay a').mouseenter(function(){
			if(!$(this).hasClass('active')){
				if(!$.browser.msie){
					$(this).stop(true, false).fadeTo('normal', 0);
				}
			}
		});
		parent.find('.thumbs .thumb .overlay a').mouseleave(function(){
			if(!$(this).hasClass('active')){
				if(!$.browser.msie){
					$(this).stop(true, false).fadeTo('normal', 1);
				}
			}
		});
		parent.find('.large-pagination img.arrow-left').click(function(){
			obj.scrollLeft(parent.find('.thumb-container .thumbs'));
		});
		parent.find('.large-pagination img.arrow-right').click(function(){
			obj.scrollRight(parent.find('.thumb-container .thumbs'),itemWidth);
		});
		parent.find('.large-pagination').children('.pager').click(function(){
			if(!$(this).hasClass('active')){
				listItem = $(this);
				var indx = parent.find('.large-pagination').children('.pager').index(listItem);
				
				obj.circleScroll(parent.find('.thumb-container .thumbs'),indx);
			}
		});
		parent.find('.thumbs .thumb').click(function(){
			var link = $(this).find('.overlay a');
			if(!link.hasClass('active')){
				parent.find('.thumbs .thumb a.active').removeClass('active');
				parent.find('.thumbs .thumb.active').removeClass('active');
				link.addClass('active');
				if(!$.browser.msie){
					parent.find('.thumbs .thumb .overlay a').stop(true,false).fadeTo('normal', 1);
				}
				$(this).addClass('active');
				if($('.fullscreen-gallery').is(':visible') || !parent.is(':visible')){
					var image = $(this).find('img').attr('title');
				}else{
					var image = $(this).find('img').attr('rel');
				}
				var description = $(this).find('img').attr('alt');
				var ind = obj.thumbs.children('.thumb').index($(this)) + 1;
				obj.changeImage(image, ind, description);
			}
		});


	},
	
	scrollLeft: function(el){
		var parent = this.element;
		var mleft = parseInt(el.css('margin-left'));
		if(mleft < 0 && !el.hasClass('scrolling')){
			el.addClass('scrolling');
			mleft += 618;
			el.animate({'margin-left': mleft+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			listItem = parent.find('.large-pagination').children('.pager.active');
			var active_index = parent.find('.large-pagination').children(' .pager').index(listItem);
			active_index-=1;
			parent.find('.large-pagination').children('.pager.active').removeClass('active');
			parent.find('.large-pagination').children('.pager:eq('+active_index+')').addClass('active');
		}
	},
	
	scrollRight: function(el,width){
		var parent = this.element;
		var mleft = parseInt(el.css('margin-left'));
		var max = (this.count-6)*width*-1;
		
		if(mleft > max && !el.hasClass('scrolling')){
			el.addClass('scrolling');
			mleft -= 618;
			el.animate({'margin-left': mleft+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			listItem = parent.find('.large-pagination').children('.pager.active');
			var active_index = parent.find('.large-pagination').children(' .pager').index(listItem);
			active_index+=1;
			parent.find('.large-pagination').children('.pager.active').removeClass('active');
			parent.find('.large-pagination').children('.pager:eq('+active_index+')').addClass('active');
		}
	},
	
	circleScroll: function(el,indx){
		var margin = indx*642*-1;
		var parent = this.element;
		
		if(!el.hasClass('scrolling')){
			el.addClass('scrolling');
			el.animate({'margin-left': margin+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			parent.find('.large-pagination').children('.pager.active').removeClass('active');
			parent.find('.large-pagination').children('.pager:eq('+indx+')').addClass('active');
		}
	},

	changeImage: function(image, ind, description){
		var parent = this.element;

		parent.find('.active-image .image-holder img').remove();
		parent.find('.active-image .preloader').show();
		parent.find('.active-image .image-holder').prepend('<img src="'+image+'" />');
		parent.find('.active-image .image-holder img').load(function(){
			var image = $(this);
			if($('.fullscreen-gallery').is(':visible')){
				var width = $(this).width() + 1;
				var margin_left = width / 2;
				$('.fullscreen-gallery .active-image .desc-block').css({ width:width, marginLeft: '-'+margin_left+'px' });
			}
			image.hide();
			parent.find('.active-image .preloader').fadeOut(function(){
				image.fadeIn();
			});
		});
		parent.find('.active-image .description').html(description);
		parent.find('.thumb-container .totals .current').html(ind);
	},

	hideThumbs: function(){
		this.mouseTimer = null;
        this.thumbsVisible = false;
        var parent = this.element;

		if($('.fullscreen-gallery').is(':visible')){
			var thumb_height = parent.find('.thumb-container').height();
			parent.find('.thumb-container').stop(true,false).animate({ marginTop:'0px' }, 1000);
		}
	},

	showThumbs: function(){
		this.mouseTimer = null;
        this.thumbsVisible = true;
        var parent = this.element;

		if($('.fullscreen-gallery').is(':visible')){
			var thumb_height = parent.find('.thumb-container').height();
			parent.find('.thumb-container').stop(true,false).animate({ marginTop:'-97px' }, 1000);
		}
	}

});

$.snippet = function(template, data) { 
	var i;
   
   for (i in data) {
		template = template.split('%7B' + i + '%7D').join(data[i]);
   	template = template.split('{' + i + '}').join(data[i]);
   }

   return template;
}

$.widget('ui.changeGallery', {

	_create: function() {
		var obj = this;
		var parent = this.element;
		this.thumbs = parent.find('.thumb-container .thumbs');
		var itemWidth = 680;
		this.count = parent.find('.six-small-gallery ').length;
		this.galleries = parent.find('.small-gallery');

		this.galleries.find('.overlay a').click(function(e){
			var gallery = $(this).closest('.small-gallery');
			obj.change(gallery);
			if(e.originalEvent!=undefined){
				$('html, body').animate({
					scrollTop: $(".gallery-container").offset().top
				}, 2000);
			}
		});

		parent.find('.small-gallery:first .overlay a').click();

		parent.find('.next-previous .previous').click(function(){
			obj.scrollLeft(parent.find('.small-galleries-infinite'));
		});
		parent.find('.next-previous .next').click(function(){
			obj.scrollRight(parent.find('.small-galleries-infinite'),itemWidth);
		});
		parent.find('.small-pagination').children('.pager').click(function(){
			if(!$(this).hasClass('active')){
				listItem = $(this);
				var indx = parent.find('.small-pagination').children('.pager').index(listItem);
				
				obj.pageScroll(parent.find('.small-galleries-infinite'),indx);
			}
		});

	},

	change: function(gallery){
		var files = gallery.find('.files .file');
		var title = gallery.find('.gallery-title strong').html();
		var file_length = files.length;
		var thumb_clone = $('.large-gallery .thumb-container .thumbs .clonable').html();
		var thumb_html = '';
		var circle_count = Math.ceil( file_length / 6 );
		var circle_clone = $('.large-gallery .thumb-container .large-pagination .clonable').html();
		var circle_html = '';
		var i = 0;
		var max_width = 110 * file_length;

		files.each(function(){
			var path = $(this).find('.detail-tiny').html();
			var description = $(this).find('.detail-description').html();
			var large = $(this).find('.detail-large').html();
			var original = $(this).find('.detail-original').html();

			thumb_html += $.snippet(thumb_clone, {
				path: path,
				description: description,
				large: large,
				original: original
			});
		});

		for(i=0;i < circle_count;i++){
			circle_html += circle_clone;
		}

		$('.gallery-container h1.title').html(title);
		$('.large-gallery .thumb-container .thumbs').children('.thumb').remove();
		$('.large-gallery .thumb-container .thumbs').append(thumb_html);
		$('.large-gallery .thumb-container .large-pagination').children('.pager').remove();
		$('.large-gallery .thumb-container .large-pagination .clonable').after(circle_html);
		$('.large-gallery').gallery();
		$('.large-gallery .thumb-container .thumbs').children('.thumb:first').click();
		$('.large-gallery .thumb-container .large-pagination').children('.pager:first').addClass('active');

		$('.fullscreen-gallery .thumb-container .thumbs').children('.thumb').remove();
		$('.fullscreen-gallery .thumb-container .thumbs').append(thumb_html);
		$('.fullscreen-gallery .thumb-container .large-pagination').children('.pager').remove();
		$('.fullscreen-gallery .thumb-container .large-pagination .clonable').after(circle_html);
		$('.fullscreen-gallery').gallery();
		$('.fullscreen-gallery .thumb-container .thumbs').css({ width: max_width+'px' });
		$('.fullscreen-gallery .thumb-container .thumbs').children('.thumb:first').click();
		$('.fullscreen-gallery .thumb-container .large-pagination').children('.pager:first').addClass('active');

	},
	
	scrollLeft: function(el){
		var mleft = parseInt(el.css('margin-left'));
		if(mleft < 0 && !el.hasClass('scrolling')){
			el.addClass('scrolling');
			mleft += 680;
			el.animate({'margin-left': mleft+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			listItem = $('.small-pagination').children('.pager.active');
			var active_index = $('.small-pagination').children(' .pager').index(listItem);
			active_index-=1;
			$('.small-pagination').children('.pager.active').removeClass('active');
			$('.small-pagination').children('.pager:eq('+active_index+')').addClass('active');
		}
	},
	
	scrollRight: function(el,width){
		var parent = this.element;
		var mleft = parseInt(el.css('margin-left'));
		var max = (this.count-1)*width*-1;
		
		if(mleft > max && !el.hasClass('scrolling')){
			el.addClass('scrolling');
			mleft -= 680;
			el.animate({'margin-left': mleft+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			listItem = $('.small-pagination').children('.pager.active');
			var active_index = $('.small-pagination').children(' .pager').index(listItem);
			active_index+=1;
			$('.small-pagination').children('.pager.active').removeClass('active');
			$('.small-pagination').children('.pager:eq('+active_index+')').addClass('active');
		}
	},
	
	pageScroll: function(el,indx){
		var margin = indx*680*-1;
		
		if(!el.hasClass('scrolling')){
			el.addClass('scrolling');
			el.animate({'margin-left': margin+'px'},1000,function(){
				el.removeClass('scrolling');
			});
			$('.small-pagination').children('.pager.active').removeClass('active');
			$('.small-pagination').children('.pager:eq('+indx+')').addClass('active');
		}
	}

});

jQuery.fn.center = function () {
	var popup = this;
	if ($.browser.msie){
		popup.css('left','0px');
		popup.css('top','0px');
	}
	var hght = $(window).height() - popup.find('.lightbox-container').outerHeight() - 100;
		popup.find('.lightbox-container').css("margin-left", "0");
		popup.find('.lightbox-container').css("margin-top", "0");
		popup.css({ position: "fixed", visibility: "hidden", display: "block" });
		popup.find('.lightbox-container').css("left", ( $('body').width() - popup.find('.lightbox-container').outerWidth() ) / 2 + "px");
		popup.find('.lightbox-container').css("top", Math.max( ( $(window).height() - popup.find('.lightbox-container').outerHeight() - 30 ), 0 ) / 2 + "px");
		
		popup.css({ position: "", visibility: "", display: "" });
	
    return this;
}

$.snippet = function(template, data) { 
	var i;
   
   for (i in data) {
		template = template.split('%7B' + i + '%7D').join(data[i]);
   	template = template.split('{' + i + '}').join(data[i]);
   }

   return template;
}

$.widget('ui.miniLightboxF', {

	_init: function(){
		var obj = this;
		var parent = this.element;
		var infoId = this.element.attr('rel');
		var collection = this.element.attr('title');
		obj.prevWidth = '100px'
		obj.prevHeight = '100px'
		$('.mini-lightbox-button-f[title="'+collection+'"]').clone().appendTo('body .temp-gallery').hide();
		
		$('#gallery-lightbox .image-title').html('');
		obj.change(infoId);

		$('#gallery-lightbox .lightbox-container .close, #gallery-lightbox .overlay').unbind().bind('click',function(){
			obj.hide();
		});
		
		$('#gallery-lightbox .lightbox-container').mouseenter(function(){
			$(this).children('.prev,.next').show();
		});
		$('#gallery-lightbox .lightbox-container').mouseleave(function(){
			$(this).children('.prev,.next').hide();
		});
		
	},
	
	change: function(infoId){
		var obj = this;
		var infoElement = $('.image-info'+infoId);
		var imgPath = infoElement.find('.image-path').html();
		//imgPath = imgPath.replace(' ','%20');
		var imgTitle = infoElement.find('.image-title').html();
		var imgDesc = infoElement.find('.image-description').html();
		
		$('.temp-gallery .clicked').removeClass('clicked');
		$('.temp-gallery .mini-lightbox-button-f[rel="'+infoId+'"]').addClass('clicked');
		
		$('#gallery-lightbox .preloader').show();
		$('#gallery-lightbox .image-container').children('img').replaceWith('<img src="'+imgPath+'" />');
		
		$('#gallery-lightbox .image-container').children('img').css({ width: obj.prevWidth, height: obj.prevHeight });

		$('#gallery-lightbox').center();
		$('#gallery-lightbox').show();
		
		$('#gallery-lightbox .image-container').children('img').load(function(){
			var currentWidth = $(this).width();
			var currentHeight = $(this).height();
			
			$(this).css({ width: 'auto', height: 'auto' });
			var maxWidth = Math.min( $(window).width()-200, $(this).width() );
			var maxHeight = Math.min( $(window).height()-200, $(this).height() );
			if( maxWidth < maxHeight ){
				$(this).css({ width: maxWidth+'px' });
				if( maxHeight < $(this).height() ){
					var height = $(this).height();
					$(this).css({ height: height+'px' });
					var maxWidth = parseInt( $(this).width() );
				}else{
					var maxHeight = parseInt( $(this).height() );
				}
			}else{
				$(this).css({ height: maxHeight+'px' });
				if( maxWidth < $(this).width() ){
					var width = $(this).width();
					$(this).css({ width: width+'px' });
					var maxHeight = parseInt( $(this).heigth() );
				}else{
					var maxWidth = parseInt( $(this).width() );
				}
			}
			
			$('#gallery-lightbox .image-container').children('img').css({ width: obj.prevWidth, height: obj.prevHeight });
			
			var leftDiff = ( maxWidth - parseInt( obj.prevWidth ) ) / 2;
			var topDiff = ( maxHeight - parseInt( obj.prevHeight ) ) / 2;
			var left = parseInt( $('#gallery-lightbox .lightbox-container').css('left') ) - leftDiff;
			var top = parseInt( $('#gallery-lightbox .lightbox-container').css('top') ) - topDiff;
			
			obj.prevWidth = maxWidth;
			obj.prevHeight = maxHeight;
			
			$('#gallery-lightbox .lightbox-container').animate({
				left: left+'px',
				top: top+'px'
			}, 500);
			
			$(this).animate({
				width: maxWidth+'px',
				height: maxHeight+'px'
			},500,function(){
				$('#gallery-lightbox .image-title').html(imgTitle);
				$('#gallery-lightbox .preloader').hide();
			});
			
			
			$(this).unbind().bind('click',function(){
				if( $('.temp-gallery .clicked').next('.mini-lightbox-button-f').length > 0 ){
					obj.change( $('.temp-gallery .clicked').next('.mini-lightbox-button-f').attr('rel') );
				}else{
					obj.change( $('.temp-gallery .mini-lightbox-button-f:first').attr('rel') );
				}
			});
			$('#gallery-lightbox .next').unbind().bind('click',function(){
				if( $('.temp-gallery .clicked').next('.mini-lightbox-button-f').length > 0 ){
					obj.change( $('.temp-gallery .clicked').next('.mini-lightbox-button-f').attr('rel') );
				}else{
					obj.change( $('.temp-gallery .mini-lightbox-button-f:first').attr('rel') );
				}
			});
			$('#gallery-lightbox .prev').unbind().bind('click',function(){
				if( $('.temp-gallery .clicked').prev('.mini-lightbox-button-f').length > 0 ){
					obj.change( $('.temp-gallery .clicked').prev('.mini-lightbox-button-f').attr('rel') );
				}else{
					obj.change( $('.temp-gallery .mini-lightbox-button-f:last').attr('rel') );
				}
			});
			
		});
	},

	hide: function(){
		var obj = this;
		$('.temp-gallery').html('');
		$('#gallery-lightbox').removeClass('centered');
		$('#gallery-lightbox').children('.close').hide();
		$('#gallery-lightbox .lightbox-container').animate({ opacity: '0' }, 500);
		$('#gallery-lightbox .overlay').animate({ opacity: '0' }, 500, function(){
			$('#gallery-lightbox').hide();
			$('#gallery-lightbox .image-container img').css({ width: 'auto', height: 'auto' });
			$('#gallery-lightbox .lightbox-container').css({ width: 'auto', height: 'auto' });
			$('#gallery-lightbox .lightbox-container .prev, #gallery-lightbox .lightbox-container .next').hide();
			
			$('#gallery-lightbox .overlay').css({ opacity: '0.5' });
			$('#gallery-lightbox .lightbox-container').css({ opacity: '1' });
			
			obj.destroy();
		});
	},

	destroy: function() {
       $.Widget.prototype.destroy.apply(this, arguments); // default destroy
        // now do other stuff particular to this widget
   }

});

$(document).ready(function(){
	$('.main-nav li').mouseenter(function(){
		$(this).children('.sub-nav').stop(true,true).slideDown();
	});
	$('.main-nav li').mouseleave(function(){
		$(this).children('.sub-nav').stop(true,true).slideUp();
	});
	
	$(window).resize(function(){
		if($('.fullscreen-gallery').is(':visible')){
			$('.fullscreen-gallery .thumb-container .thumb-infinite .next-side').remove();
			$('.fullscreen-gallery .thumb-container .thumb-infinite .prev-side').remove();
			var thumb_width = $('.fullscreen-gallery .thumb-container .thumbs').width();
			var doc_width = $(document).width();
			if(thumb_width > doc_width){
				var diff = thumb_width - doc_width;
				$('.fullscreen-gallery .thumb-container .thumb-infinite').append('<a class="next-side" href="javascript:void(0);">&#187;</a>');
				$('.fullscreen-gallery .thumb-container .thumb-infinite').append('<a class="prev-side" href="javascript:void(0);">&#171;</a>');
				$('.fullscreen-gallery .thumb-container .next-side').click(function(){
					var orig_margin = parseInt($('.fullscreen-gallery .thumb-container .thumbs').css('margin-left')) * -1;
					var count = $('.fullscreen-gallery .thumb-container .thumbs').children('.thumb').length;
					var el = $('.fullscreen-gallery .thumb-container .thumbs');

					if((doc_width + orig_margin) / 110 < count){
						if(!el.hasClass('scrolling')){
							el.addClass('scrolling');
							el.animate({
								marginLeft: '-='+doc_width+'px'
							}, 1000, function(){
								el.removeClass('scrolling');
							});
						}
					}
				});
				$('.fullscreen-gallery .thumb-container .prev-side').click(function(){
					var orig_margin = parseInt($('.fullscreen-gallery .thumb-container .thumbs').css('margin-left'));
					var el = $('.fullscreen-gallery .thumb-container .thumbs');

					if(orig_margin != 0){
						if(!el.hasClass('scrolling')){
							el.addClass('scrolling');

							if( orig_margin < doc_width ){
								
								el.animate({
									marginLeft: '0px'
								}, 1000, function(){
									el.removeClass('scrolling');
								});

							}else{

								el.animate({
									marginLeft: '+='+doc_width+'px'
								}, 1000, function(){
									el.removeClass('scrolling');
								});

							}
						}
					}
				});
			}
		}
	});

	$('.large-gallery').gallery();
	$('.fullscreen-gallery').gallery();

	$('.large-gallery .full-screen').click(function(){
		$('.large-gallery .desc-block').css({ height:'0px' });

		listItem = $('.large-gallery .thumbs').children('.thumb.active');
		var active_index = $('.large-gallery .thumbs').children('.thumb').index(listItem);

		$('.fullscreen-gallery .thumbs').children('.thumb:eq('+active_index+')').click();
		$('.fullscreen-gallery').css({ display: 'block', opacity:'0' }).fadeTo(500, 1, function(){
			$('.wrap').hide();
			$('.fullscreen-gallery .active-img img').hide();
			$('.fullscreen-gallery .active-image .preloader').fadeOut(function(){
				$('.fullscreen-gallery .active-img img').fadeIn();
			});
		});
		$('.fullscreen-gallery .desc-block').css({ width: $('.fullscreen-gallery .active-image img').width()+1, marginTop: '0px' }).hide();
		$(window).trigger('resize');
	});
	$('.fullscreen-gallery .close').click(function(){
		$('.wrap').show();
		$('.fullscreen-gallery').fadeTo(500, 0, function(){
			$('.fullscreen-gallery').hide();
		});
	});

	$('.small-galleries').changeGallery();
	
	$('.support .opening-times').click(function(){
		var element = $('.support .open-popup');
		
		if( element.is(':visible') ){
			element.stop(true,true).fadeOut();
		}else{
			element.stop(true,true).fadeIn();
		}
	
		return false;
	});
	
	$('.tab-btn').click(function(){
		if( !$(this).parent().hasClass('active') ){
			var block = '#'+$(this).attr('rel');
			$('.tab-btn').parent().removeClass('active');
			$('.tab-cont').hide();
			$(block).stop(true,true).fadeIn();
			$(this).parent().addClass('active');
		}
		
		return false;
	});
	
	var rotators = $('.front-rotate');
	var counter = 0;
	$(rotators).hide();
	$(rotators[0]).show();
	setInterval(function() {
		$(rotators[counter]).fadeOut('slow');
		 counter++;
		 if (counter == rotators.length) {
			 counter = 0;
		 }
		$(rotators[counter]).fadeIn(1000);
	}, 15000);
	
	$('.front-left .slider .slider-btn .vip-btn').click(function(){
		$('.front-left .slider-inside').stop(true,true).animate({
			marginLeft: '-438px'
		}, 400, 'linear' );
		
		return false;
	});
	
	$('.front-left .slider .slider-btn .single-btn').click(function(){
		$('.front-left .slider-inside').stop(true,true).animate({
			marginLeft: '0px'
		}, 400, 'linear' );
		
		return false;
	});
	
	$('#lightbox a.close, #lightbox .overlay').click(function(){
		$(this).closest('#lightbox').fadeOut('fast');
		$(this).closest('#lightbox').find('.lightbox-content').html('');
	});
	
	$('.lightbox-button').click(function(){
		var content = $(this).attr('rel');
		
		$('#lightbox .lightbox-content').html('');
		$(content).clone().appendTo( $('#lightbox .lightbox-content') ).show();
		$('#lightbox').center().fadeIn('fast');
		
		return false;
	});

	$('.mini-lightbox-button-f').click(function(){
		$(this).miniLightboxF();
		return false;
	});
	
	$('.container .front-banner-right .watch-short-btn').click(function(){
		$('#video-short').show();
	});
	
});

