jQuery(document).ready(function() {

$("#inline").fancybox();

//Show Banner
$(".main_image .desc").show(); //Show Banner
$(".main_image .block").animate({ opacity: 0.75 }, 1 ); //Set Opacity

//Click and Hover events for thumbnail list
$(".image_thumb ul li:first").addClass('active'); 
$(".image_thumb ul li").click(function(){ 
	var mioID = $(this).attr('id');
	window.location=$("#"+mioID+" .block a").attr('href'); return false;
});

$(".image_thumb ul li").mouseover(function(){ 
//Set Variables
var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	

if ($(this).is(".active")) {  //If it's already active, then...
return false; // Don't click through
} else {
	
	$(".main_image .block").html(imgDesc).animate({ 
	opacity: 0.85,	
	marginBottom: "0" 
	}, 500);
	$(".main_image img").attr({ 
				src: imgTitle , 
				alt: imgAlt
				}).animate({
					opacity: 0.85,	
					marginBottom: "0" 
				}, 500);
}

$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
$(this).addClass('active');  //add class of 'active' on this list only
return false;

}) .hover(function(){
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});

//Toggle Teaser

$("a.collapse").click(function(){
$(".main_image .block").slideToggle();
$("a.collapse").toggleClass("show");
});
$("a.collapse").click(function(){
	$(".main_image .block").slideToggle('slow');
	$("a.collapse").toggleClass("show");
});

});


function slideSwitch() {
    var $active = jQuery('#slideshow span.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshow span:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshow span:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
   $active.removeClass('active last-active');
        });
}


function slideSwitch2() {
    var $active = jQuery('#slideshowV2 span.active');

    if ( $active.length == 0 ) $active = jQuery('#slideshowV2 span:last');

    var $next =  $active.next().length ? $active.next()
        : jQuery('#slideshowV2 span:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
   $active.removeClass('active last-active');
        });
}


jQuery(document).ready(function(){

 setInterval( "slideSwitch()", 4000 ); 
 setInterval( "slideSwitch2()", 4000 ); 
    
 });







window.onload = function () {
            var container = $('div.sliderGallery');
            var ul = $('ul', container);
            
            var itemsWidth = ul.innerWidth() - container.outerWidth();
            
            container.css('overflow', 'hidden');  // move auto to noscript style to avoid flicker
            
            $('.slider', container).slider({
                min: 0,
                max: itemsWidth,
                handle: '.ui-slider-handle',
                stop: function (event, ui) {
                    ul.animate({'left' : ui.value * -1}, 500);
                },
                slide: function (event, ui) {
                    ul.css('left', ui.value * -1);
                }
            });
	       $(".btn-left").click(function(){
		       var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
			       if(elValue > 0) {
			          elValue = elValue - 100;
			          if(elValue < 0) {
		             elValue = 0;
		          }
			     $(".sliderGallery .slider").slider('value', elValue);
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			       }
			});
			$(".btn-right").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
			       if(elValue < itemsWidth) {
			          elValue = elValue + 100; 
			          if(elValue > itemsWidth) {
		             elValue = itemsWidth;
		          }
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			       }
			});
			$("span.end").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
		             elValue = itemsWidth;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			});
			$("span.start").click(function(){
			  var elValue = $('.slider', container).slider('option', 'value');
		       // alert (elValue);
		             elValue = 0;
		          $(".sliderGallery .slider").slider('value', elValue); 
		          $(".sliderGallery ul").animate({'left' : elValue * -1}, 500);
			});
        };