// JavaScript Document
function initTabs(tabcontentclass,listclass){
//Default Action
	$(tabcontentclass).hide(); //Hide all content
	$(listclass+" li:first").addClass("active").show(); //Activate first tab
	$(tabcontentclass+':first').show(); //Show first tab content
	
	//On Click Event
	$(listclass+" li").click(function() {
		$(listclass+" li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(tabcontentclass).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
		return false;
	});	
}

function slidingPanels(){
	//$('.free-online-btn, .share-btn').click();
	$('.side-close, .free-online-btn, .share-btn').click(function(){
		if(jQuery('.side-button').hasClass('on')){
			jQuery('.side-button').animate({right:"-437px"}).removeClass("on");		
		}
		else{
			jQuery('.side-button').animate({right:"0"}).addClass("on");		
		}
	});
	$(".more-link").click(function(){
		
		if($('.drop-down-cont').hasClass('on')){
		$('.drop-down-cont').animate({marginTop:"-35px"}).removeClass("on");
		//$('.body-cont').animate({marginTop:"-46px"}).removeClass('on');
		}
		else{
			$('.drop-down-cont').animate({marginTop:"0px"}).addClass("on");	
			//$('.body-cont').animate({marginTop:"-10px"}).addClass('on');
		}
	});
	var mouse_is_inside = false;

 	jQuery('.side-button, .drop-down-cont').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });

    jQuery(".body-cont").mouseup(function(){ 
        if(!mouse_is_inside && jQuery('.side-button').hasClass("on"))  { 
                jQuery('.side-button').animate({right:"-437px"}).removeClass("on");
        }
      if(!mouse_is_inside && jQuery('.drop-down-cont').hasClass("on"))  { 
                jQuery('.drop-down-cont').animate({marginTop:"-35px"}).removeClass("on");
				//jQuery('.body-cont').animate({marginTop:"-46px"}).removeClass("on"); 
        }
    });	
}
function initwebappCarousel(container,prevbtn,nextbtn){
	$(container).cycle({
		fx:     'scrollHorz',
		prev: prevbtn,
		next: nextbtn,
        speed:  800,
        timeout: 0,
		pause: 1
        
	});
}
function initCarousel(){
	$("#carousel").cycle({
		fx:     'scrollHorz',
		prev: '.prev-btn',
		next: '.next-btn',
        speed:  800,
        timeout: 5000,
		pause: 1,
        pager:  '#nav',
		pagerAnchorBuilder: function(idx, slide) {
            return '<li><a href="#"></a></li>';
        }
	});
	$("#carousel2").jCarouselLite({
		btnNext: ".link-section .next-btn",
		btnPrev: ".link-section .prev-btn",
		visible: 4,
		speed: 800
	});	
}

function innerBanner(){
	jQuery(".banner-cont").appendTo(".banner-glow .container");	
}
function removeSelectedState(){
	$('.sub-tag ul.right li').each(function(){
	if($(this).hasClass('selected')){
    	$('.sub-tag ul.left li:first').removeClass('selected');
	}
	});
}
function arrangeFeaturesItems(){
	$('.promote-info:first').addClass('first');
	$('.promote-info:odd .feature-text').removeClass('left').addClass('right');
	$('.promote-info:odd .feature-img ').removeClass('right').addClass('left');	
}
function redTabFeaturesPage(){
	$('.red-tab').addClass('feature-page');	
}

function grabSubmenu(){
	$('.sub-tag ul.right').html($('#nav_530506 li.selected ul').html());
		$(".sub-tag ul.left li:first a").html("<span>"+$("#nav_530506 li.selected a span").text()+"</span>");
}
function seoSidebarLeft(){
	$('.seo-report').addClass('left-subpage');	
}
function filterPortfolioitems(){
	//$('.filter-cont ul.left li:first').addClass('current');
	$('.portfolio-items li').each(function(){
		$(this).attr('class',$(this).attr('class').replace(',',' '));
	});
	
	$('#filterby a').click(function(e){
		e.preventDefault();
		$('#filterby li.current').removeClass('current');
		$(this).parent().addClass('current');
		var selector = $(this).attr('data-filter');
  			$('.portfolio-items').isotope({ 
			filter: selector ,
			animationEngine: 'best-available',
			animationOptions: {
			 duration: 300,
			 easing: 'linear',
			 queue: false
			}
		});
		
	});
	/*$('.filter-cont ul.left a').click(function() {
		$(this).css('outline','none');
		$('.filter-cont ul.left .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).text().toLowerCase().replace(' ','');
				
		if(filterVal == 'allitems') {
			$('ul.portfolio-items li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			$('ul.portfolio-items li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});	*/

}
function selectNewsLink(){
	$('#nav_530506 a').each(function(){
	  if(window.location.pathname.indexOf('_blog') == 1){
		if($(this).attr('href').indexOf('_blog') == 1){
			$(this).parent('li').addClass('selected')
		}
	  }    
	});	
}
function webappMenuState(){
	$('#nav_530506 li:contains("Our Work")').addClass('selected');
	$(".sub-tag ul.left li:first a").html("<span>"+$("#nav_530506 li.selected a span").text()+"</span>");
	$('.sub-tag ul.right').html($('#nav_530506 li.selected ul').html());
}
function fixBlogpagination(){
	$('#pagination').contents().unwrap();
	$('.page-links').contents().filter(function(){ return this.nodeType != 1; }).wrap('<li class="no-a"></li>');
	$('.page-links').contents().not('li.no-a').wrap('<li></li>');
	
	$('#previouspage').html('&lt; Prev');
	$('#nextpage').html('Next &gt;');
}
function trimBlogPagination(){
	$(window).load(function(){
$('.page-links li').each(function() { 
	   var vr1 = $.trim($(this).html());
	   if (vr1 == '' ){ $(this).remove(); } 
	 });	
	});
}
function grabNextPrevPortfolioLink(){
	$("#other-projects a").each(function(){
//console.log($(this).attr("href")window.location.pathname);
		if(window.location.pathname == $(this).attr("href")){
			var prevlink = $(this).prev('a').attr("href");
			var nextlink = $(this).next('a').attr("href");
			if(prevlink === undefined){
				$('.prev-proj-btn').attr('href', $("#other-projects a").last().attr("href"));
			}
			else{
				$('.prev-proj-btn').attr('href', prevlink);
			}
			if(nextlink === undefined){
				$('.next-proj-btn').attr('href', $("#other-projects a").first().attr("href"));
			}
			else{
				$('.next-proj-btn').attr('href', nextlink);
			}
		}	
	});
}
function blogCommentDateFix(){
	$('.date-text').each(function(){
	var date = $(this).text().split(' ');
	var dateseg = date[0].split('-');
	var day = dateseg[0];
	var month = '';
	var year = dateseg[2];
	if(dateseg[0] == '1' || dateseg[0] == '01'){
		day += 'st';
	}
	else if(dateseg[0] == '2' || dateseg[0] == '02'){
		day += 'nd';
	}
	else if(dateseg[0] == '3' || dateseg[0] == '03'){
		day += 'rd';
	}
	else{
		day+= 'th';
	}
	if(dateseg[1] == 'Jan'){
		month = 'January';
	}
	else if(dateseg[1] == 'Feb'){
		month = 'February';
	}
	else if(dateseg[1] == 'Mar'){
		month = 'March';
	}
	else if(dateseg[1] == 'Apr'){
		month = 'April';
	}
	else if(dateseg[1] == 'Jun'){
		month = 'June';
	}
	else if(dateseg[1] == 'Jul'){
		month = 'July';
	}
	else if(dateseg[1] == 'Aug'){
		month = 'August';
	}
	else if(dateseg[1] == 'Sep'){
		month = 'September';
	}
	else if(dateseg[1] == 'Oct'){
		month = 'October';
	}
	else if(dateseg[1] == 'Nov'){
		month = 'November';
	}
	else if(dateseg[1] == 'Dec'){
		month = 'December';
	}
	$(this).text(day+' '+month+' '+year);
	});		
}
$(document).ready(function(){
	$('#showMap').colorbox({width:"80%", height:"600px", inline:true, href:"#map"});
	$('.com-img').each(function(){
		var divlink = $(this).find('a').attr('href');
		$(this).click(function(){
			window.location.href = divlink;
		});
	});
	if($('.sub-tag ul.right li').hasClass('selected')){
    	$('.sub-tag ul.left li').removeClass('selected');
	}
	grabSubmenu();
	removeSelectedState();
});
