// Cleverlance.com startup jQery script ver. 0.5

var bannerTimer = null;

function theRotator() {
	//Set the opacity of all images to 0
	$('div.rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div.rotator ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	
	bannerTimer = setInterval('rotate()',6000);
}

function rotate() {	
	//Get the first image
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	
	//Un-comment the 3 lines below to get the images in random order
	
	//var sibs = current.siblings();
        //var rndNum = Math.floor(Math.random() * sibs.length );
        //var next = $( sibs[ rndNum ] );
			

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
};

function switchBan(bannerId) {
	if(bannerTimer) {
		clearInterval(bannerTimer);
	}

	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
    if ( current.length == 0 ) current = $('div.rotator ul li:first');
	var next = $(bannerId);

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
}

$(document).ready(function() {		
	//Load the slideshow
	theRotator();
	$('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE
});

function updateSlider()
{
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      var h = $(window).height();
	  var st = $('.clv-bottom-menu').offset().top;
      
      // whether that's below the form
      if (y+h <= st) {
        // if so, ad the fixed class
        $('#slider').addClass('fixed');
      } else {
        // otherwise remove it
        $('#slider').removeClass('fixed');
      }
}

// init CREATE IT slider
$(document).ready(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
      var y = $(this).scrollTop();
      var h = $(window).height();
	  var st = $('.clv-bottom-menu').offset().top;
      
      // whether that's below the form
      if (y+h <= st) {
        // if so, ad the fixed class
        $('#slider').addClass('fixed');
      }
      
    $(window).scroll(function (event) {
		updateSlider();
    });
  }
});

function gup( name ){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^&#]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if( results == null )    return "";  else    return results[1];}

// init clance-tabs
$(document).ready(function() {
 
	//Default Action
	$(".tab_content").hide(); //Hide all content
	var hash = '#'+gup('tab'); //get hash
	if(hash != "#"){
		$('ul.tabs a[href="'+hash+'"]').parent().addClass("active").show(); //Activate tab according hash
		$(hash).show(); //Show tab
		updateSlider();
	} else {
		$("ul.tabs li:first").addClass("active").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		updateSlider();
	}
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		updateSlider();
		return false;
	});
 
});

// superfish menu
$(document).ready(function() {
  $(".clv-menu ul").superfish({
     delay:       1000,
     animation:   {opacity:'show',height:'show'},
     speed:       'fast',
     autoArrows:  false,
     dropShadows: false
  });
  $(".clv-menu ul ul").superfish({
     delay:       1000,
     animation:   {opacity:'show',width:'show'},
     speed:       'fast',
     autoArrows:  false,
     dropShadows: false
  });
});



