// JavaScript Document

function theRotator() {
            //Set the opacity of all images to 0
            $('ul#gallery_images li').css({opacity: 0.0});

            //Get the first image and display it (gets set to full opacity)
            $('ul#gallery_images li:first').css({opacity: 1.0});

            //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds

            setInterval('rotate()',6000);

}
	

	function rotate() {
	//Get the first image
	var current = ($('ul#gallery_images li.show')?  $('ul#gallery_images li.show') : $('ul#gallery_images li:first'));
       
    if ( current.length == 0 ) current = $('ul#gallery_images 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')) ? $('ul#gallery_images li:first') :current.next()) : $('ul#gallery_images 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}, 1500);

	//Hide the current image
	current.animate({opacity: 0.0}, 1500)
	.removeClass('show');
        
        
        var highlight = $("#gallery_images li").index($('.show'));
        $('ul.picker li').eq(highlight).addClass('show').css({backgroundPosition:"0 -24px"})
            .animate(
			{backgroundPosition:"0 3px"}, 
			{duration:1300})
        .siblings().removeClass("show");
        
}

//service page tabs

$(document).ready(function() {
			
	$("#subs").addClass("hidden"); // hide dropdown list.
		
		$('#portal').mouseover(function() {
			
				$("#subs").removeClass('hidden');	
					
		});	
		
		$('#portal').mouseout(function() {
			
				$("#subs").addClass('hidden');					
		});
	//service page tabs
        
        var openTab = (window.location.hash);
        if(openTab.length){
            $("a[href='"+location.hash+"']").parent().addClass('active');
        $(openTab).siblings().addClass('hidden');
        
        } else {        
        $('ul.tabsNav li:first').addClass('active');		
        $('#web-design').siblings().addClass('hidden'); 
        }
        //click funtion
        $("ul.tabsNav li").click(function() {

        $("ul.tabsNav li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tabContent").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
        });

		
	
	
		
		
						   
		$('#footer li a, .services li a').mouseover(function() {
				$(this).stop() .animate( {	"paddingLeft" : "10px", "paddingRight" : "10px"});	
		});
		$('#footer li a, .services li a').mouseout(function() {
				$(this).stop() .animate( {"paddingLeft" : "0px", "paddingRight" : "0px"});	
		});
		

// cycle through list for blurb
		$('#cycle').cycle({ 
			fx:'uncover', 
			sync:0,
			timeout:5000,
			speed:3000,
			pause:1,
			autostop:1, 
    		next:   '#next', 
    		prev:   '#prev'
			});
		
		//clearform
		
		$('#jForm form').clearForm();
		
	
		
// submit

$('#jform').bind('submit', function() {
            $(this).ajaxSubmit({
				target: '#response', 
				success: function() { 
            $('#response').fadeIn('1500');
			
			
        } 
            });
            return false; // <-- important!
        });

	

theRotator();
        $('ul#gallery_images li').fadeIn(1000);
        $('ul#gallery_images li').fadeIn(1000); // tweek for IE

//tooltips qtip2 plugin

$('#packages a[title]').qtip({
    position:{
        my:'bottom center',
        at:'top center',
        target:'event',
        viewport:$(window)
    },
    
    content: {
      text: function(api){
          var tipContent = $(this).attr('alt')+'-tip';
          return  $("."+tipContent);
      },
      title: {text:function(api){
              return $(this).attr('alt');
        }
      }
      
   },
  style: {
  classes: 'ui-tooltip-rounded ui-tooltip-shadow'
   }
   
})

//remove last border in popular list
$('ul#popular li').last().addClass('no-border-bottom');


//landing page gallery 

$(function(){
			$('#gallery').slides({
				preload: true,
				preloadImage: 'img/loading.gif',
				play: 7000,
				pause: 1000,
                                slideSpeed:1500,
				hoverPause: true,
                                generateNextPrev:false,
                                slideEasing: "easeOutQuad",
				animationStart: function(current){
					$('.caption').animate({
						top:-200
					},100);
					if (window.console && console.log) {
						// example return of current slide number
						console.log('animationStart on slide: ', current);
					};
				},
				animationComplete: function(current){
					$('.caption').animate({
						top:40
					},1200);
					if (window.console && console.log) {
						// example return of current slide number
						console.log('animationComplete on slide: ', current);
					};
				},
				slidesLoaded: function() {
					$('.caption').animate({
						top:40
					},1200);
				}
			});
                        //set pagination width.
                        var paginationWidth = 14*($(".pagination li").length);
                        $("ul.pagination").css("width",paginationWidth);

		});
                


});




