/*
	                                                       __                  
	                                                      /\ \__  __           
	  ___ ___     ___     ___    ___     ___ ___      __  \ \ ,_\/\_\    ___     ____   
	/' __` __`\  / __`\  /'___\ / __`\ /' __` __`\  /'__`\ \ \ \/\/\ \  /'___\  /',__\ 
	/\ \/\ \/\ \/\ \L\ \/\ \__//\ \L\ \/\ \/\ \/\ \/\ \L\.\_\ \ \_\ \ \/\ \__/ /\__, `\
	\ \_\ \_\ \_\ \____/\ \____\ \____/\ \_\ \_\ \_\ \__/.\_\\ \__\\ \_\ \____\\/\____/
	 \/_/\/_/\/_/\/___/  \/____/\/___/  \/_/\/_/\/_/\/__/\/_/ \/__/ \/_/\/____/ \/___/ 

	© raffael ziegler
*/



/* 
thanks to paul irish!
http://paulirish.com/2009/fighting-the-font-face-fout/ */

$(document).ready(function(){
	
	// - - - - - - - - - - - - - -  MENU - - - - - - - - - - - - - -  //
	var all_menu_items = $('.menu-item > a');
	var menu_items_with_submenu = $('.menu-item:has(.sub-menu) > a');
	var selected_menu_items = $('.current-menu-parent:has(.sub-menu) > a');
	var not_selected_menu_items =  $('.menu-item:not(.current-menu-parent):has(.sub-menu) > a');
	
	var selected_menu_items_on_single = $('.menu-item:has(.sub-menu:has(.current-menu-parent)) > a');
	
	//$('.menu-item :has(.sub-menu:has(.current-menu-item)) > .sub-menu').css('display','block');
	
	menu_items_with_submenu.css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_down_dithered.png)');
	menu_items_with_submenu.css('background-repeat','no-repeat');
	menu_items_with_submenu.css('background-position','85% 50%');
	
	selected_menu_items_on_single.css('color', '#cc0000');
	$('.sub-menu:has(.current-menu-parent)').css('display', 'block');
	
	selected_menu_items.css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_up_dithered.png)');
	
	
	all_menu_items.click(function() {
	  $(this).parent().find('> .sub-menu').toggle('slow', function() {
		return false
	  });
	  // $(this).parent().find('.sub-menu').clearQueue();
	  
	});
	
	
	not_selected_menu_items.toggle (
		function () {
			$(this).css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_up_dithered.png)');
	  }
	  ,
		function () {
			$(this).css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_down_dithered.png)');
			
		 }
	  
	);
	
	selected_menu_items.toggle (
		function () {
			$(this).css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_down_dithered.png)');
	  }
	  ,
		function () {
			$(this).css('background-image','url(http://wpdev.msavisuals.com/wp-content/themes/msav_01/images/msav_arrow_up_dithered.png)');
			
		 }
	  
	);
	
	
	
	
	$('.menu-item > a').hover(
		function () {
			$(this).animate({
				backgroundColor: "#f6f6f6",
				//backgroundColor: "#f9f3f4", // rose
				//backgroundColor: "#d4000d",
				//color: "dithered"
			 }, 250, 'linear');	
			 $(this).clearQueue();
	  }
	  ,
		function () {
			$(this).animate({
				backgroundColor: "white",
				//color: "black"
			 }, 250, 'linear');
			 $(this).clearQueue();	
		 }
	  
	);
	
	// - - - - - - - - - - - - - -  MENU - - - - - - - - - - - - - -  //

	
	$('.slide').hover(
		function () {
			$('.slide_title', this).animate({
				opacity: '1'
			 }, 250, 'linear');	
		
	  }
	  ,
		function () {
			$('.slide_title',this).animate({
				opacity: '0'
			 }, 250, 'linear');
			
		 }
	  
	);
	

	
	
	/*
	$('.post_preview').hover(
		function () {
			$(".post_preview_description",this).animate({
				opacity: .3
			  }, 250, 'linear');
			  $(".post_preview_description p",this).animate({
				opacity: 1
			  }, 250, 'linear');
			  
			  
			  $(".post_preview_front",this).animate({
				opacity: 0
			  }, 250, 'linear');
		}
		 ,
		 function () {
			$(".post_preview_description",this).animate({
				opacity: 0
			}, 250, 'linear');
			
			
			
			$(".post_preview_description p",this).animate({
			opacity: 0
			}, 250, 'linear');
			
			
			
			$(".post_preview_front",this).animate({
				opacity: 1
			  }, 250, 'linear');
		
		}
		
	);
	*/
	
	initGallery();
	
});

function initGallery(){
	var currentPosition = 0;
  	var slideWidth = 450;
  	var slides = $('.slide');
  	var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
    .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
  $('#slideshow')
    .prepend('<span class="control" id="leftControl"></span>')
    .append('<span class="control" id="rightControl"></span>');

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
  }	
}

