/* Author:

*/

/*
 * Head-Rotator Script
 *
 * 
 */
$(document).ready(function() {
    $('.slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	
});


/*
 * Isotope Sorting Script
 *
 * http://isotope.metafizzy.co/demos/filtering.html
 */

$(function(){
      
      var $container = $('#cart-container');

		// If FF use Jquery for animation
		if ($.browser.mozilla) {
			$container.isotope({
				itemSelector : '.product',
				animationEngine : 'jquery',
			});
		} else {
			$container.isotope({
				itemSelector : '.product'
			});
		}
      
      
      var $optionSets = $('#options .option-set'),
          $optionLinks = $optionSets.find('a');

      $optionLinks.click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return false;
        }
        var $optionSet = $this.parents('.option-set');
        $optionSet.find('.selected').removeClass('selected');
        $this.addClass('selected');
  
        // make option object dynamically, i.e. { filter: '.my-filter-class' }
        var options = {},
            key = $optionSet.attr('data-option-key'),
            value = $this.attr('data-filter');
        // parse 'false' as false boolean
        value = value === 'false' ? false : value;
        options[ key ] = value;
        if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
          // changes in layout modes need extra logic
          changeLayoutMode( $this, options )
        } else {
          // otherwise, apply new options
          $container.isotope( options );
        }
        
        return false;
      });

      
    });












/*
 * Popup window script
 *
 * http://yensdesign.com/2008/09/how-to-create-a-stunning-and-smooth-popup-using-jquery/
 */


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

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

//disabling popup with jQuery magic!
function disablePopup(){

    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $(popupContainer).fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(winType){
	
	popupContainer = '#popup-'+winType;

    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $(popupContainer).height();
    var popupWidth = $(popupContainer).width();
    //centering
    $(popupContainer).css({
        "position": "absolute",
        "top": 150, //windowHeight/2-popupHeight/2+50,
        "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!
    $(".button-contact").click(function(){
        //centering with css
        centerPopup('contact');
        //load popup
        loadPopup('contact');
    });
    
    $(".button-faqs").click(function(){
        //centering with css
        centerPopup('faqs');
        //load popup
        loadPopup('faqs');
    });
                
    //CLOSING POPUP
    //Click the x event!
    $(".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();
        }
    });

});

