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

var currentLI = 0;
var lengthLI = 0;
/*
 * To redirect the site to 'search/search_string'
 * to get the search results
 */
//function submitSearch(){
//	var str = $('#search_txt').val();
//	var trimmed = str.replace(/^\s+|\s+$/g, '') ;
//	document.location = "/search/"+trimmed;
//}
/*
 * To show the related category projects in project slider
 * mac_development - is the hidden field id which contains the selected value from the drop down.
 */
function showCategoryProjects(){
	//alert('Hello..');
	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++;			
		}
	/*
	if(timer<=3){
		b = setTimeout("bubbleEffect()", 1168);
	}else{
		isShake = false;
		clearTimeout(b);
		timer=0;
	}
	*/	
}

/*
 * To aninate the slider elements [group by group].
 * 160 - to slide one element
 * 160 * n [no of elements to animate]
 */
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()", 6000);
}

function selectRandomMenu(){
	// To select random tab menu 
    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"});
	
	var sto = setTimeout(function() {
		$('#sb_footer').append("<div id='cipI7l' style='z-index:100;position:absolute'></div><div id='scpI7l' style='display:inline'></div><div id='sdpI7l' style='display:none'></div><div style='display:inline'><a href='http://www.providesupport.com?messenger=sourcebits'>Customer Service</a></div></noscript>");
		var sepI7l = document.createElement('script');
		sepI7l.type='text/javascript';
		var sepI7ls=(location.protocol.indexOf('https')==0?'https':'http')+'://image.providesupport.com/js/sourcebits/safe-standard.js?ps_h=pI7l\u0026ps_t='+new Date().getTime()+'\u0026online-image=http%3A//sbnew.publishy.com/images/buttons/onlinechat.png\u0026offline-image=http%3A//sbnew.publishy.com/images/buttons/offlinechat.png';
		setTimeout(function() {
			sepI7l.src=sepI7ls;document.getElementById('sdpI7l').appendChild(sepI7l);	
		},1);
	}, 1000);
	
	
	//<script type='text/javascript'></script><noscript>
	
	/*	HOME Page: Services menu
     *  To retrive the featured project of the services.
     *  id is taken from the service menu li attribute [ex: "service_mac","service_web", etc..]
     *  The Project results are pre displayed in the homepage itself on page load.
     *  on cliking of the menu item the service id [ex: "service_mac"] is taken and added the
     *  "_featured_proj" which is project id for that related service. and displayed it
     *  in FADEIN effect.
     */
    //selectRandomMenu();
    
	$('#service-menu li').livequery('click',function(i){
		$('#service-menu li').each(function(){
			$(this).removeClass('active');
		});
		//console.log($(this).attr('name'));
		clearTimeout(aut);
		currentLI=($(this).attr('name'))-1;		
		//currentLI = 0;
		$(this).addClass('active');
		var featured_proj = $(this).attr('id')+'_featured_proj';
		$('.content-inner>div').hide();
		$('#'+featured_proj).fadeIn(500,function(){
			//autoPlay();
		});
	});
	
	// This is for service sub menu display on mouse hover on service tab menu in the header.
	/*
	$('#sub-menu').hover(function(){
		$(this).addClass('hover'); //chin
					
	},
	function(){
		$(this).removeClass('hover'); //chin		
	});
	
	$('#about_sub_menu').hover(function(){
		$(this).addClass('hover'); //chin					
	},
	function(){
		$(this).removeClass('hover'); //chin		
	});
	
	*/
	/*
	 * SERVICS Page:
	 * All projects are pre displayed and on clicking the project in slider the
	 * related project has been displayed using Fadein Effect
	 */
	$('.jcarousel-item').click(function(){
		var projId = $(this).attr('id');
		projId = '#'+projId+'_div';
		$('#project_container>div').hide();
		$(projId).fadeIn(1200);
	});

	// To initiate the drop down component.
	jQuery.TTcombo();


    
	/*
	 * To display the GRID view.
	 */
	$('#grid_icon').click(function(){
		//$('#myslider').css({left: "0px"});
		$('#gal_view').hide();
		//$('#gal_view').css({height:"0px",overflow:"hidden"});
    	//$('.thumbs').css({height:"0px",overflow:"hidden"});
		$('.grid-view').fadeIn(1200);
		// This wil change the grid icon and text.
		$(this).hide();
		$('#gal_icon').fadeIn(1200);
		$('#icon_text').html('Gallery View');
	});

	   
});