/**

**/
jQuery(document).ready(function($) {
  
  //$('ul.qtrans_language_chooser li.active').remove();
  //$('ul.qtrans_language_chooser').prepend('ul.qtrans_language_chooser li.active');
  
  $('.lang ul').hover(
    function () {
      $('.lang ul').css('height','auto');
      return false;
    },
    function () {
      $('.lang ul').css('height','30px');
      return false;
    }
);
  
 
	// initialize SuperBGImage
	$('#thumbs').superbgimage();
	//$('#content').fadeTo('slow', 1);

	$('.box1').hover(
		function () {
			$('.box1 .inner').stop().animate({
			    top: '-162'
			}, 200, function() {
		    // Animation complete.
			});
	  	}, 
	  function () {
	  	$('.box1 .inner').stop().animate({
				top: '0'
			}, 200, function() {
		    // Animation complete.
			});
	});	

	$('.box4').hover(
		function () {
			$('.box4 .inner').stop().animate({
			    top: '-172'
			}, 200, function() {
		    // Animation complete.
			});
	  	}, 
	  function () {
	  	$('.box4 .inner').stop().animate({
				top: '0'
			}, 200, function() {
		    // Animation complete.
			});
	});	
	
	$('.next_img').click(function() {
  		$('#thumbs').nextSlide();
  		return false;
  	});
  	
  	$('.prev_img').click(function() {
  		$('#thumbs').prevSlide();
  		return false;
  	});
  	
  	/* functions */
  	$('a.advance_0').addClass('active');
  	
  	$('a.advance').click(function() {	
		var the_position = $(this).attr('rel');
		

		$('.the_navigation').find('a').removeClass('active');
  		$(this).addClass('active');

		$(".functions_inner").animate({
			"left": -the_position*585
		}, 500, function() {
			
			
		} );
	  	return false;
  		
  	});
  	
  	$('.kids_s2').append('<div class="clear"></div><div class="kids_s2_div"></div><div class="clear"></div>');

  	$('.hide_gfx').click(function() {
  		$('#content').fadeOut('slow');
  		$('a.show_gfx').show();
  		if ( $('#thumbs').children().size() > 1 ) {
	  		$('.prev_img').show();
   			$('.next_img').show();
  		}
   		return false;
  	});
  	
  	$('a.show_gfx').click(function() {
  		$('#content').fadeIn('slow');
  		$('a.show_gfx').hide();
  		$('.prev_img').hide();
   		$('.next_img').hide()
  	});
  	  	
  	$('.materials img').click(function() {
  		var imgClicked = $(this).attr("title");
  		//alert ( imgClicked );
  		$('.materials').find('img').removeClass('active');
  		$(this).addClass('active');
		$('.work_s3').css('background-image', 'url(/wp-content/themes/boilerplate/images/bg_' + imgClicked + '.jpg)');
  	});
  	
  	var size = $('.materials').size();
	var position = $(".materials_inner").position();
  	$('a.prev').hide();
  	var disabled = false;
  	var scroll_amount = 558;

  	if ( size > 3 ) var stop_scroll_at = 552;
  	if ( size > 6 ) var stop_scroll_at = 1104;
  	
  	$('a.prev').click(function() {
		if ( position.left < 0 && !disabled ) {
			$('a.next').fadeIn('fast');
	  		disabled = true;
			
			$('.materials_inner').animate({
				left: '+='+scroll_amount
				}, 500, function() {
		  			position = $(".materials_inner").position();
					if ( position.left == 5 ) {
		    			$('a.prev').fadeOut('fast');
		    		}
	  				disabled = false;
				});
		}
  	  	return false;
	});

	$('a.next').click(function() {
		if ( position.left > -stop_scroll_at && !disabled ) {
			$('a.prev').fadeIn('fast');
			disabled = true;
			
			$('.materials_inner').animate({
				left: '-='+scroll_amount
				}, 500, function() {
					position = $(".materials_inner").position();
					if ( position.left < -stop_scroll_at ) {
		    			$('a.next').fadeOut('fast');
		    		}
	  				disabled = false;
				});
		}
  	  	return false;
	});
	
	// smooth scroll the page
	$('.scrollPage').click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		return false;
	});
	
	// expand sub-menu
	$('#sticky .tab').click(function() {
  	  	if ( $('#sticky a').is(':hidden') ) {
  	  		$('#sticky a').fadeIn('slow');	
  	  	}
  	  	else {
  	  		$('#sticky a').fadeOut('fast');
  	  	}
	});
	
	// make the submenu stick when scrolling
	$(window).scroll(function() {
	   scroll_sticky();
	});
	
	//
	function scroll_sticky() {
		if ($(window).scrollTop() > 200 ) {
			$('#to_the_top').fadeIn('slow');
		}
		
		if ($(window).scrollTop() < 200 ) {
			$('#to_the_top').fadeOut('fast');

		}
		
		var position = $('#sticky').offset();
		var my_offset = $(window).scrollTop()-position.top;

		if ( my_offset > 0 ) {
			$('#sticky .sticky_content').css('position', 'fixed');
			$('#sticky .sticky_content').css('top', '0px');
		}
		else {
			$('#sticky .sticky_content').css('position', 'relative');
		}
	}

 


  	



}); /* jQuery */





