var isAnimStopped = true;
var isShake = false;
var  b;
var  aut;
var timer=0;
var isSet=0;

var currentLI = 0;
var lengthLI = 0;

function showCategoryProjects(){
	var catIdClass = '.cat_'+$('#mac_development').val();
	$('#myslider tr td').hide();
	$('.grid-element').hide();
	if(catIdClass == '.cat_1' || catIdClass == '.cat_9' || catIdClass == '.cat_12'){
		$('#myslider tr td').fadeIn(1200);
		$('.grid-element').fadeIn(1200);
	}
	$(catIdClass).fadeIn(1200);
	$('.grid-view>'+catIdClass).fadeIn(1200);
}

function bubbleEffect(){
	var jqNode = $(".subscribe-input");
	if(isShake){ 
			jqNode.animate({top:"-=15px"},250,'easeOutQuad').animate({top:"+=15px"},250,'easeInQuad');
			timer++;			
		}
}

function slideCarousel(elm, sign) {
	var	currentProductId = 0;
	var no = parseInt(elm.css('left'));
	var nofElms = 160 * 5;

	isAnimStopped = false;
	if(sign == '+') { no += nofElms; }
	else { no -= nofElms; }
	if(no > 0) {
		elm.animate({left:"0px"}, 600, 'easeInQuad', function() {
			isAnimStopped = true;
			setSession(no);
		});	
	}else{
		elm.animate({left:no}, 600, 'easeInQuad', function() {
			isAnimStopped = true;
			setSession(no);
		});	
	}		
}


function autoPlay(){
	currentLI++;
	if(currentLI > lengthLI) { currentLI = 1; }
	
	var currTab = $('#service-menu li:nth-child('+currentLI+')').attr('id');
	$('#service-menu li').each(function(){
			$(this).removeClass('active');
		});
	$('#'+currTab).addClass('active');
	
	var currFeatProj = '#'+currTab+'_featured_proj';
	$('.content-inner>div').hide();
	$(currFeatProj).fadeIn(1900);
	aut = setTimeout("autoPlay()", 21000);
}

function selectRandomMenu(){
    var randomnumber=Math.floor(Math.random()*3);
    randomnumber += 1;
    $('#service-menu li:nth-child('+randomnumber+')').addClass('active');
    var menuid = $('#service-menu li:nth-child('+randomnumber+')').attr('id');
    $('#'+menuid+'_featured_proj').fadeIn(1200);
}
$(document).ready(function(){
	
	$('.right').css({position:"relative",top:"0px",right:"0px"});
	
	
	
    
	$('#service-menu li').livequery('click',function(i){
		$('#service-menu li').each(function(){
			$(this).removeClass('active');
		});
		clearTimeout(aut);
		currentLI=($(this).attr('name'))-1;		
		$(this).addClass('active');
		var featured_proj = $(this).attr('id')+'_featured_proj';
		$('.content-inner>div').hide();
		$('#'+featured_proj).fadeIn(500,function(){
		});
	});
	
	$('.jcarousel-item').click(function(){
		var projId = $(this).attr('id');
		projId = '#'+projId+'_div';
		$('#project_container>div').hide();
		$(projId).fadeIn(1200);
	});

	jQuery.TTcombo();

	 $('#msg_subject li').livequery('click',function(){
	 	$('#content_title').html($(this).attr("title"));
	 	var msgid = $(this).attr('id');
	 	var title = $(this).attr('title');
	 	$('#cont_input').val(title);
	 	$('#cont').val(title);
	 	$('.combo_list_item li').removeClass('selected');
	 	$('#cont_input_'+msgid).addClass('selected');
	 	hideCallBack();
	 });
	$('.reset').click(function(){
		$('div#main_form :input').val('');
		$('#cont_input').val('Choose a subject');		
	});

	$(".subscribe-email").livequery('click', function() {
		
		$('#err').html('');
		$('#subscribe').css({background: "none"});
	    var menu = $('#' + $(this).attr('id').replace('_id', '_input'));
	    if (/^none$/.test(menu.css('display'))) {
            $(".subscribe-input").fadeOut("fast");
            menu.fadeIn("fast");
            //$('#subscribe').focus();
            isShake = true;
			bubbleEffect();       	   
	    }else{
	    	isShake = false;
			clearTimeout(b);
	    	menu.fadeOut("fast");
	    }
		return false;
    });
    
    $('#subsc_email_input').livequery('click', function(e) {
    	if($.browser.msie){
    		window.event.cancelBubble = true;
    	}else{
    		e.stopPropagation();
    	}
    });
   
	$('.subscribe-input').livequery('click',function(){
		$(this).fadeIn('fast');
    });
	$(document).bind('click',function() {
        $(".subscribe-input").fadeOut("fast");
    });

	$('#grid_icon').click(function(){
		$('#gal_view').hide();
		$('.grid-view').fadeIn(1200);
		$(this).hide();
		$('#gal_icon').fadeIn(1200);
		$('#icon_text').html('Gallery View');
	});


	$('#gal_icon').click(function(){
		$('.grid-view').hide();
		$('#gal_view').fadeIn(1200);
		$('.launchgallery').css({opacity:"1",filter:"alpha(opacity=100)"});
		$(this).hide();
		$('#grid_icon').fadeIn(1200);
		$('#icon_text').html('Grid View');
		$('#gal_view').css({height:"auto",overflow:""});
		$('.thumbs').css({height:"150px",overflow:""});			
        
		if(isSet==0){
			setCarousel();
			isSet=1;
		}		
		
	});

	 $('#callback_btn').click(function(){
	 	$('#success_msg_contact').addClass('hide');
	 	$('#content_title').html('Request a Callback');
	 	showCallBack();
	 });
	 $('.close-icon').click(function(){
	 	$('#content_title').html('Contact us');
	 	hideCallBack();
	 });
	 
	 
	 $(document).ready(function(){

		// If we are not on home page, load Google Analytics code dynamicallt
		if ($('#jsincludes').length > 0) {
			//setTimeout(function() { $.getScript(scriptLocation+'includes.js'); }, 100);

			var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

			var gac = document.createElement('script');
			gac.type = 'text/javascript';
			gac.src = gaJsHost + 'google-analytics.com/ga.js';

			document.getElementById('jsincludes').appendChild(gac);

			try { var pageTracker = _gat._getTracker("UA-1489692-1"); pageTracker._trackPageview(); } catch(err) {}

		}

	  	$("#sub-menu, #about_sub_menu").hover(
	  		function(){
	  			if($(this).hasClass('active')){
	  				$(this).addClass('hover');
		  	  		$(this).fadeIn(500);
	  			}else{
	  				$(this).hide();
	  				$(this).addClass('hover');
	  			}
	  					  	  
	  		},
	  		function() {	  			  		
		  		$(this).removeClass('hover');
	  		}
	  	);

	  });


		// set opacity to nill on page load
		$(".grid-view .grid-element span.anim").css("opacity","0");
		
		// on mouse over
		$(".grid-view .grid-element").hover(
			function () {
				// animate opacity to full
				$(this).find("span.anim").stop().animate({
					opacity: 1
				}, 'fast');
			},
			// on mouse out
			function () {
				// animate opacity to nill
				$(this).find("span.anim").stop().animate({
				opacity: 0
			}, 'slow');
		});
		
		// set opacity to nill on page load
		$(".jcarousel-item div span.anim").css("opacity","0");
		
		// on mouse over
		$(".jcarousel-item div").hover(
			function () {
				// animate opacity to full
				$(this).find("span.anim").stop().animate({
					opacity: 1
				}, 'fast');
			},
			// on mouse out
			function () {
				// animate opacity to nill
				$(this).find("span.anim").stop().animate({
				opacity: 0
			}, 'slow');
		});
});
