 // VERTICALLY ALIGN FUNCTION
			$.fn.vAlign = function(margin) {
				this.wrapInner('<div class="vAlign"></div>')
				return this.each(function(i){
				var vAlign=$(this).find('.vAlign')
				var ah = vAlign.height();
				var ph = vAlign.parent().height();
				var mh = Math.ceil((ph-ah) / 2);
				
				if(margin=="margin"){
				vAlign.css('margin-top', mh);
				}
				else
				vAlign.css('padding-top', mh);
				});
			};
 function galleryInit(id){
				
  if($('.gallery').length){
	 // assign the slider to a variable
	  var slider = $('#gallery-'+id).bxSlider({
		controls: true,
		mode: 'fade',
		autoControls: true,
		auto: true,
		nextText: 'next',
		prevText: 'previous',
		startText: '',																
		stopText: '',
		speed: 1000,
		pause: 5000
	  });

	  // assign a click event to the external thumbnails
	  var thumbs=$('.thumbs[rel="'+id+'"] a');
	  
	  thumbs.click(function(){
	   var thumbIndex = thumbs.index(this);
		// call the "goToSlide" public function
		slider.goToSlide(thumbIndex);
	  
		// remove all active classes
		thumbs.removeClass('pager-active');
		// assisgn "pager-active" to clicked thumb
		$(this).addClass('pager-active');
		// very important! you must kill the links default behavior
		return false;
	  });

	  // assign "pager-active" class to the first thumb
	  $('.thumbs[rel="'+id+'"] a:first').addClass('pager-active');
	  
	  return slider;
 }

}
 function galleryHide(id,galleries){
	$('#gallery-'+id).parent().parent().fadeOut();
	$('.thumbs[rel="'+id+'"]').fadeOut(function(){galleries[parseInt(id)-1].stopShow()});
	
} 
 function galleryShow(id,scrollbar,galleries){
	galleries[parseInt(id)-1].goToSlide(0);
	//function(){galleries[parseInt(id)-1].startShow();}
	$('#gallery-'+id).parent().parent().fadeIn();
	$('.albums a').removeClass('active');
	$('.albums a[rel="'+id+'"]').addClass('active');
	$('.thumbs[rel="'+id+'"]').fadeIn(
		function(){
			scrollbar.find('.overview').height($('.thumbs[rel="'+id+'"]').height())
			scrollbar.tinyscrollbar({size: 579}); 
		});
	
} 
			 
$(window).load(function(){	
		$('.tutorials li').vAlign('margin');
		$('.tutorials').css({'visibility':'visible'});
		
		/*product slider*/
			 if($('#pr_slider').length){
			 // assign the slider to a variable
			  var slider = $('#pr_slider').bxSlider({
				controls: false,
				mode: 'fade',
				auto: true,
				pause: 5000
			  });

			  // assign a click event to the external thumbnails
			  $('.thumbs a').click(function(){
			   var thumbIndex = $('.thumbs a').index(this);
				// call the "goToSlide" public function
				slider.goToSlide(thumbIndex);
			  
				// remove all active classes
				$('.thumbs a').removeClass('pager-active');
				// assisgn "pager-active" to clicked thumb
				$(this).addClass('pager-active');
				// very important! you must kill the links default behavior
				return false;
			  });

			  // assign "pager-active" class to the first thumb
			  $('.thumbs a:first').addClass('pager-active');
			  
			  }
		
			
		/*Columns equial height*/
		var height=0;
		$('.columns>div').each(function(){
			if($(this).height()>height) height=$(this).height();
			
		})
		
		$('.columns>div').height(height);

	})
	  $(document).ready(function(){
			Cufon.set('fontFamily', 'Bebas').replace('.create li>a')('.rotate')
			$('.product-b').each(function(){
				if(!$(this).find('a').length) $(this).remove();
			})
			$('.product-b.shop-nav').each(function(){
				
				var prev=$('a[title="Previous Page"]',$(this)).attr('href');
				var next=$('a[title="Next Page"]',$(this)).attr('href');
				var html='';
				if(prev!=undefined){
					html+='<div class="prev"><a href="'+prev+'">previous</a></div>'
				}
				html+='<span></span>'
				if(next!=undefined){
					
					html+='<div class="next"><a href="'+next+'">next</a></div>'
				}
				$(this).empty().html(html);
			
			})
			
			$(".products li").equalHeights(); 
			var widgetHeight=0;
			$('.f-widgets>div').each(function(){
				widgetHeight=$(this).height()>widgetHeight?$(this).height():widgetHeight;
			})
			$('.f-widgets>div').height(widgetHeight);
				
			if($('.gal-wrap').length){
				  
				  var galleries=[
				  
				  galleryInit(1),
				  galleryInit(2),
				  galleryInit(3),
				  galleryInit(4),
				  galleryInit(5)
					]
				  
				  /*Scrollbar*/
				var scroll=$('#scrollbar');
				scroll.tinyscrollbar({size: 579});
				
				galleryShow(1,scroll,galleries)
					
					
				$('.albums a').click(function(){
					if(!$(this).hasClass('active')){
						galleryHide($('.albums a.active').attr('rel'),galleries);
						galleryShow($(this).attr('rel'),scroll,galleries);
					}
					return false;
				})
			}
			
			$('.create li>a').vAlign();
			
			$('#slides').slides({effect: 'fade',crossfade: true,play:6000,fadeSpeed: 600});
			$('.circle-nav li').hover(
					function(){
						$(this).find('.hover').removeClass('hover');

						$(this).find('.circle-popup').addClass('hover');
					},function(){$(this).parent().parent().find('.hover').removeClass('hover');})
				
			/*tutorials items position*/
			$('.tutorials li').each(function(){
				var rel=parseInt($(this).attr('rel'))
				var posY=Math.floor(rel/4)+(rel%4==0?0:1);
				var posX=rel%4+(rel%4==0?4:0);
				var marginY=posY%2==0?55:0;
				var marginX=posY%2==0?0:92;
				
				var shiftX=185;
				var shiftY=106;
				
				if(rel){
					if(posY%2==0){
						$(this).css({top:(posY/2-1)*shiftY+marginY})
					} else{
						$(this).css({top:((posY-1)/2)*shiftY+marginY})
					}
				
					$(this).css({left:(posX-1)*shiftX+marginX})
					
				
					
				}
			})
			
			$('.tutorials li').hover(function(){
				$(this).find('span:first').fadeOut(100);
				$(this).find('a').fadeIn(100);
			},function(){
				$(this).find('span:first').fadeIn(100);
				$(this).find('a').fadeOut(100);
			});
			$('.tutorials li a').fancybox({'padding':7,'maxWidth':560,'maxHeight':315});
			
			
			
			
	   });
	
