jQuery.noConflict();
jQuery(document).ready(function($){
   var $prev = $('img.wtk-gallery-scrollButtons-left');//prev button
	var	$next = $('img.wtk-gallery-scrollButtons-right');//next button
    var $panels = $('#wtk-gallery-slider .wtk-gallery-scrollContainer > div');
    var $container = $('#wtk-gallery-slider .wtk-gallery-scrollContainer');


    // if false, we'll float all the panels left and fix the width 
    // of the container
    var horizontal = true;

    // float the panels left if we're going horizontal
    if (horizontal) {
        $panels.css({
            'float' : 'left',
            'position' : 'relative' // IE fix to ensure overflow is hidden
        });

		$containerWidth = $('.wtk-gallery-scrollContainer').offsetWidth;
        // calculate a new width for the container (so it holds all panels)
        //$container.css('width', $panels[0].offsetWidth * $panels.length);
        $container.css('width', $containerWidth);
    }
    
    
    // collect the scroll object, at the same time apply the hidden overflow
    // to remove the default scrollbars that will appear
    var $scroll = $('#wtk-gallery-slider .wtk-gallery-scroll').css('overflow', 'hidden');

    // apply our left + right buttons
    $scroll
        .before('<img class="wtk-gallery-scrollButtons wtk-gallery-scrollButtons-left" src="/wp-content/themes/silverio/img/clear.gif" height="500" width="180" />')
        .after('<img class="wtk-gallery-scrollButtons wtk-gallery-scrollButtons-right" src="/wp-content/themes/silverio/img/clear.gif" height="500" width="180" />');





/* --------------- slideshow thumbs --------------- */
	//use pixastic image manipulation to desaturate one of the two thumbnails
	//using "normal" javascript because pixastic's jquery function wasn't working in Safari
	
	$(".desat").each(function(){
		Pixastic.process($(this).get(0), "desaturate", {average : false});
	});
	

	//hides the desaturated thumbnail and shows the normal thumbnail
	thumbFocus=function(thumb){
		//make the argument a jquery object
		var t=$(thumb);

		//note: IE doesn't play nice with fading transparent PNGs, so we only enable this feature for other browsers.
		//see: http://stackoverflow.com/questions/1375646/jquery-animate-opacity-doesnt-work-properly-on-ie/1990728#1990728
		//if(!$.browser.msie){
			t.find(".desat").fadeTo("fast",0);
			t.find(".normal").fadeTo("fast",1);
			t.find(".inner-shadow").fadeTo("fast",1);
		//}
	};
	//hides the normal thumbnail and shows the desaturated thumbnail
	thumbBlur=function(thumb){
		var t=$(thumb);
		//if thumbnail is active, we never want to blur it !$.browser.msie && 
		if(!t.hasClass("activeSlide")){
			t.find(".desat").fadeTo("fast",0.2);	
			t.find(".normal").fadeTo("fast",.35);
			t.find(".inner-shadow").fadeTo("fast",1);
		}		
	};
	//call the focus & blur functions on hover in & out
	$("#pager a").hover(
		function(){
			thumbFocus(this);
		},
		function(){
			thumbBlur(this);
		}
	);
		 

    // go find the navigation link that has this target and select the nav
    function trigger(data) {        
	
				//find all the other thumbnails, remove class "active", and blur them. 
				$('#pager li').find('a[class="activeSlide"]').removeClass("activeSlide").each(function(){
					thumbBlur(this);
				});
				//then use that index to find the correct thumbnail, give it class "active", and focus it
				$('#pager li').find('a[href="#' + data.id + '"]').addClass("activeSlide").each(function(){
					thumbFocus(this);
				});	
	}
    	
    var scrollOptions = {
        target: $scroll, // the element that has the overflow

        // can be a selector which will be relative to the target
        items: $panels,

        navigation: '.wtk-gallery-navigation a',

        // selectors are NOT relative to document, i.e. make sure they're unique
        prev: 'img.wtk-gallery-scrollButtons-left', 
        next: 'img.wtk-gallery-scrollButtons-right',

        // allow the scroll effect to run both directions
        axis: 'xy',

        onAfter: trigger, // our final callback
		
		// offset is used to move to *exactly* the right place, since I'm using
  	  	// padding on my example, I need to subtract the amount of padding to
    	// the offset.  Try removing this to get a good idea of the effect
        offset: -170,

        // duration of the sliding effect
        duration: 500,
        
        //auto scroll constantly
		//interval: 1,
        
        // easing - can be used with the easing plugin: 
        // http://gsgd.co.uk/sandbox/jquery/easing/
        easing: 'easeInOutExpo',
       
        //stop prev arrow from scrolling when at beginning and next when at end
        cycle:false, 
		
		onBefore:function( e, elem, $scroll, $panels, pos ){		   
    		var $prev = $('img.wtk-gallery-scrollButtons-left');//prev button
			var	$next = $('img.wtk-gallery-scrollButtons-right');//next button

			$prev.add($next).fadeIn();
		
			if( pos == 0 )
				$prev.fadeOut();
			else if( pos == $('#wtk-gallery-slider .wtk-gallery-scrollContainer > div').length-1)
				$next.fadeOut();
		}
 };


	$('li#wtk-gallery-navigation-start').click(function() {$('img.wtk-gallery-scrollButtons-left').fadeOut();});
	$('li#wtk-gallery-navigation-end').click(function() {$('img.wtk-gallery-scrollButtons-right').fadeOut();});
	
	
    // apply serialScroll to the slider - we chose this plugin because it 
    // supports// the indexed next and previous scroll along with hooking 
    // in to our navigation.
    $('#wtk-gallery-slider').serialScroll(scrollOptions);

	
    // now apply localScroll to hook any other arbitrary links to trigger 
    // the effect
    $('ul.thumbs').localScroll(scrollOptions);

    // finally, if the URL has a hash, move the slider in to position, 
    // setting the duration to 1 because I don't want it to scroll in the
    // very first page load.  We don't always need this, but it ensures
    // the positioning is absolutely spot on when the pages loads.
    scrollOptions.duration = 1;
    $.localScroll.hash(scrollOptions);



 });
