$(document).ready(function(){
	
	// New News ticker
	
	$(function(){
		$('.news').vTicker({ 
			speed: 500,
			pause: 5000,
			animation: 'fade',
			mousePause: true,
			showItems: 1,
			direction: 'up',
			height: 120
		});
	});
	
	var newscounter = 0;
	var news = $('#newsOne, #newsTwo, #newsThree, #newsFour, #newsFive');

	
	function showNews () {
        news.fadeOut(0) // hide all divs
            .filter(function (index) { return index == newscounter % 3; }) // figure out correct div to show
			.fadeIn('slow');							   
			
        newscounter++;

    } // 

	showNews();// show first div    

	
	setInterval(function () {
        showNews(); // show next div
    }, 8 * 500); // do this every 10 seconds 
	
	///////////////////////////////////////////////////////////////
	var blogcounter = 0;
	var blog = $('#blogOne, #blogTwo');

	
	function showblog () {
        blog.fadeOut(0) // hide all divs
            .filter(function (index) { return index == blogcounter % 2; }) // figure out correct div to show
			.fadeIn('slow');							   
			
        blogcounter++;

    } // 

	showblog();// show first div    

	
	setInterval(function () {
        showblog(); // show next div
    }, 8 * 500); // do this every 10 seconds 
	
	//////////////////////////////////////////////////////////////////
	
	var counter = 0,
    divs = $('#one, #two, #three, #four, #five, #six');
	
	function showDiv () {
        divs.fadeOut(0) // hide all divs
            .filter(function (index) { return index == counter % 6; }) // figure out correct div to show
			.fadeIn('slow');
        counter++;

    }
	
	showDiv();
	
	setInterval(function () {
        showDiv(); // show next div
    }, 15 * 500); // do this every 10 seconds  
	
	$('#forward').bind('click', function(){
		// Determine new position
		divs.hide();
		showDiv();
    });
	
	$('#back').bind('click', function(){
		// Determine new positio
		divs.hide();
		counter--;
		counter--;
		if(counter<1) {counter = 6;}
		showDiv();
    });
	
	//about us
	var lcounter = 0;
    var divsl = $('#lone, #ltwo, #lthree, #lfour, #lfive, #lsix, #lseven, #leight, #lnine');
	
	function showDivl () {
        divsl.fadeOut(0) // hide all divs
            .filter(function (index) { return index == lcounter % 9; }) // figure out correct div to show
			.fadeIn('slow');
        lcounter++;

    }
	
	showDivl();
	
	setInterval(function () {
        showDivl(); // show next div
    }, 15 * 1000); // do this every 10 seconds  
	
	$('#lforward').bind('click', function(){
		// Determine new position
		divsl.hide();
		showDivl();
    });
	
	$('#lback').bind('click', function(){
		// Determine new position
		divsl.hide();
		lcounter--;
		lcounter--;
		if(lcounter<1){ lcounter = 5;}
		showDivl();
    });
	
	
// NEW Slideshow
$('#slideshowHolder').jqFancyTransitions({ 
		effect: '', // wave, zipper, curtain
		width: 950, // width of panel
		height: 268, // height of panel
		strips: 20, // number of strips
		delay: 5000, // delay between images in ms
		stripDelay: 50, // delay beetwen strips in ms
		titleOpacity: 0.0, // opacity of title
		titleSpeed: 1000, // speed of title appereance in ms
		position: 'alternate', // top, bottom, alternate, curtain
		direction: 'fountainAlternate', // left, right, alternate, random, fountain, fountainAlternate
		navigation: true, // prev and next navigation buttons
		links: true // show images as links
	});	
	
	
// New Animated hovers
	$(".webdesign_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 0)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px 0"},{duration:500});}
	);
	$(".webapps_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -214px)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px -214px"},{duration:500});}
	);
	$(".print_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -428px)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px -428px"},{duration:500});}
	);
	$(".onlinemarketing_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -107px)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px -107px"},{duration:500});}
	);
	$(".design_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -535px)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px -535px"},{duration:500});}
	);
	$(".hosting_anim").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -321px)"},{duration:500});},
		function(){$(this).stop().animate({backgroundPosition: "-472px -321px"},{duration:500});}
	);
	
// New Animated hovers
	$(".animateblog").hover(
		function(){$(this).stop().animate({backgroundPosition:"(0 -43px)"},{duration:500});},
		function(){
			$(this).stop().animate(
					{backgroundPosition: " 0 0"}, 
					{duration:500}
			);
		}
	);

$("#socialnetworks .social_buttons").hover(function(){
		$(this).stop().animate(
					{marginLeft:"0px"}, 
					{duration:500}
		);
	},
	function(){
			$(this).stop().animate(
					{marginLeft:"-20px"}, 
					{duration:500}
			);
		}
	);
// Animate Call me back
	$("#call_btn").hover(
		function(){$(this).stop().animate({marginLeft:"-354px"},{duration:500});},
		function(){$(this).stop().animate({marginLeft:"-15px"},{duration:500});}
	);
	
// Animate Hints and tips
	$("#hints_btn").hover(
		function(){$(this).stop().animate({marginLeft:"-354px"},{duration:500});},
		function(){$(this).stop().animate({marginLeft:"-15px"},{duration:500});}
	);
// Tabbed Content

	$('.noneselected').mouseenter(function(){
		$(this).stop().animate({backgroundPosition : '0 29px'});	
	});
	
	$('.content_tabs a').mouseout(function(){
		var isselected = $(this).attr("class");
			if(isselected=='noneselected'){
				$('.noneselected').stop().animate({backgroundPosition : '0 0'});
			}
	});

	$('.content_tabs a').click(function(){
		var tabid = $(this).attr("name");
		// Change Button/Tab
		$('.content_tabs a').removeClass('selected').addClass('noneselected').css({backgroundPosition : '0 0'});
		$(this).removeClass('noneselected').addClass('selected').css({backgroundPosition : '0 29px'});
		// Change Content Div
		$('.content_body').children('div').hide();
		$('#' + tabid).show();
		
		return false;
	});	
		
//New Case Studies Viewpoint
$('.viewport').mouseenter(function(e) {
        $(this).children('a').children('img').animate({ height: '150', left: '0', top: '0', width: '220'}, 100);
        $(this).children('a').children('span').fadeIn(200);
    }).mouseleave(function(e) {
        $(this).children('a').children('img').animate({ height: '200', left: '-20', top: '-20', width: '270'}, 100);
        $(this).children('a').children('span').fadeOut(200);
    });
	
//New adjuster
$('.viewport span').each(function(){
        if($(this).height() > 100){
            $(this).css('line-height', '25px');
			$(this).css('padding-top', '45px');
        }
    });
	
//hover menu
	$("#nav li").hover(
		function(){
			//alert($(this).children("a").attr('class'));
			
			if($(this).children("a").attr('class')=='item about'){
				$(this).children("a").css({backgroundPosition:'-120px -56px'});
				}
			if($(this).children("a").attr('class')=='item services'){
				$(this).children("a").css({backgroundPosition:'-255px -56px'});
				}	
			if($(this).children("a").attr('class')=='item blog'){
				$(this).children("a").css({backgroundPosition:'-670px -56px'});
				}	
		
			if($(this).children("ul").css('display')=='none') {
				$(this).children("ul").slideDown();
			}
		},
		function(){
			
				if($(this).children("a").attr('class')=='item about'){
					$(this).children("a").css({backgroundPosition:'-120px -0px'});
				}
				if($(this).children("a").attr('class')=='item services'){
					$(this).children("a").css({backgroundPosition:'-255px -0px'});
				}	
				if($(this).children("a").attr('class')=='item blog'){
					$(this).children("a").css({backgroundPosition:'-670px -0px'});
				}
				
			$(this).children("ul").slideUp('fast', function(){
				// Animation complete.
				
			  });
		}
	);
	
	 $("#nav li ul").hover(
		function(){
			$(this).parent().children("a").addClass('item_sel');
		},
		
		function(){
			$(this).parent().children("a").removeClass('item_sel');
		}
	);
});
