/* SUPERFISH */
$(document).ready(function(){
	$(".sf-menu ul").superfish();
});

/* SLIDESHOW DETALHE */
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 560;
  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">Clicking moves left</span>')
    .append('<span class="control" id="rightControl">Clicking moves right</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() }
  }	
});

/* SLIDESHOW DETALHE */
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 560;
  var slides = $('.slide2');
  var numberOfSlides = slides.length;

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

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

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

  // Insert controls in the DOM
  $('#slideshow2')
    .prepend('<span class="control2" id="leftControl2">Clicking moves left</span>')
    .append('<span class="control2" id="rightControl2">Clicking moves right</span>');

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

  // Create event listeners for .controls clicks
  $('.control2')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl2') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner2').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){ $('#leftControl2').hide() } else{ $('#leftControl2').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl2').hide() } else{ $('#rightControl2').show() }
  }	
});

/* SLIDESHOW DETALHE */
$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 560;
  var slides = $('.slide3');
  var numberOfSlides = slides.length;

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

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

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

  // Insert controls in the DOM
  $('#slideshow3')
    .prepend('<span class="control3" id="leftControl3">Clicking moves left</span>')
    .append('<span class="control3" id="rightControl3">Clicking moves right</span>');

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

  // Create event listeners for .controls clicks
  $('.control3')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl3') ? currentPosition+1 : currentPosition-1;
    
	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner3').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){ $('#leftControl3').hide() } else{ $('#leftControl3').show() }
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){ $('#rightControl3').hide() } else{ $('#rightControl3').show() }
  }	
});


/* HOME SPOTLIGHT */
$(window).load(function(){
	var spotlight = {
		// the opacity of the "transparent" images - change it if you like
		opacity : 0.1,
		// the vars bellow are for width and height of the images so we can make the &lt;li&gt; same size */
		imgWidth : $('.home-spotlight ul li').width(), 
		imgHeight : $('.home-spotlight ul li').height() 			
	};
	//set the width and height of the list items same as the images
	$('.home-spotlight ul li').css({ 'width' : spotlight.imgWidth, 'height' : spotlight.imgHeight });
	//when mouse over the list item...
	$('.home-spotlight ul li').hover(function(){
		//...find the image inside of it and add active class to it and change opacity to 1 (no transparency)
		$(this).addClass('active').stop().animate({ 'opacity' : spotlight.opacity}, 1000);
		//get the other list items and change the opacity of the images inside it to the one we have set in the spotlight array 
		//$(this).siblings('li').stop().animate({ 'opacity' : 1}, 1000)
		//when mouse leave...
	}, function(){
		//... find the image inside of the list item we just left and remove the active class
		$(this).removeClass('active');
	});
	//when mouse leaves the unordered list...
	$('.home-spotlight').bind('mouseleave',function(){
		//find the images and change the opacity to 1 (fully visible)
		$(this).find('.image').stop().animate({ 'opacity' : 1}, 1000);
	});
});


/* RESULT SPOTLIGHT */
$(window).load(function(){
	var spotlight = {
		// the opacity of the "transparent" images - change it if you like
		opacity : 0.2,
		/*the vars bellow are for width and height of the images so we can make the &lt;li&gt; same size */
		imgWidth : $('.images ul li').width(), 
		imgHeight : $('.images ul li').height() 			
	};
	//set the width and height of the list items same as the images
	$('.images ul li').css({ 'width' : spotlight.imgWidth, 'height' : spotlight.imgHeight });
	//when mouse over the list item...
	$('.images ul li').hover(function(){
		//...find the image inside of it and add active class to it and change opacity to 1 (no transparency)
		$(this).addClass('active').stop().animate({ 'opacity' : 1}, 300);
		//get the other list items and change the opacity of the images inside it to the one we have set in the spotlight array 
		$(this).siblings('li').stop().animate({ 'opacity' : spotlight.opacity}, 300)
		//when mouse leave...
	}, function(){
		//... find the image inside of the list item we just left and remove the active class
		$(this).removeClass('active');
	});
	//when mouse leaves the unordered list...
	$('.images').bind('mouseleave',function(){
		//find the images and change the opacity to 1 (fully visible)
		$(this).find('.image').stop().animate({ 'opacity' : 1}, 300);
	});
});



/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#detail-popup").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#detail-popup").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#detail-popup").height();
	var popupWidth = $("#detail-popup").width();
	//centering
	$("#detail-popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$(".image img").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#detail-popupClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

