/* EXTRAS */
//actionscript CALL
(function($){$.fn.externalInterface=function(args){this.each(function(){if(typeof(args.method)!='undefined'){try{if(typeof(args.args)!='undefined'){var data=this[args.method](args.args)}else{var data=this[args.method]()}if(typeof(args.success)!='undefined'){args.success(data)}}catch(error){if(typeof(args.error)!='undefined'){args.error(error)}}}});return this}})(jQuery);

/* author Remy Sharp url http://remysharp.com/2009/01/26/element-in-view-event-plugin/ */
(function($){function getViewportHeight(){var height=window.innerHeight;var mode=document.compatMode;if((mode||!$.support.boxModel)){height=(mode=="CSS1Compat")?document.documentElement.clientHeight:document.body.clientHeight}return height}$(window).scroll(function(){var vpH=getViewportHeight(),scrolltop=(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop),elems=[];$.each($.cache,function(){if(this.events&&this.events.inview){elems.push(this.handle.elem)}});if(elems.length){$(elems).each(function(){var $el=$(this),top=$el.offset().top,height=$el.height(),inview=$el.data("inview")||false;if(scrolltop>(top+height)||scrolltop+vpH<top){if(inview){$el.data("inview",false);$el.trigger("inview",[false])}}else{if(scrolltop<(top+height)){if(!inview){$el.data("inview",true);$el.trigger("inview",[true])}}}})}});$(function(){$(window).scroll()})})(jQuery);

/* Anchor Slider by Cedric Dugas - Http://www.position-absolute.com */
jQuery.fn.anchorAnimate=function(settings){settings=jQuery.extend({speed:1100},settings);return this.each(function(){var caller=this;$(caller).click(function(event){event.preventDefault();var elementClick=$(caller).attr('href');var destination=$(elementClick).offset().top;if($.browser.opera){$('html').stop().animate({scrollTop:destination},{duration:settings.speed,queue:false,complete:function(){window.location.hash=elementClick}})}else{$('html, body').stop().animate({scrollTop:destination},{duration:settings.speed,queue:false,complete:function(){window.location.hash=elementClick}})}$('.anchorlink').each(function(){$(this).parent().removeClass('current')});$(this).parent().addClass('current');return false})})}



// GLOBAL VARIABLES OF THIS SITE
var path = window.location.hash;

// COLUMNS EQUAL HEIGHT
function setEqualHeight(columns){var tallestcolumn=0;columns.each(function(){currentHeight=$(this).height();if(currentHeight>tallestcolumn){tallestcolumn=currentHeight}});columns.height(tallestcolumn)};

// FUNCTION TO DETECT HEIGHT CONTENT
function setHgthCtntAndRpstMenu(){
	var heightcontent = $('.HeightContent');
	var windowheight = $(window).height();
	
	heightcontent.each(function(){
		if(($(this).height()) < windowheight){
			$(this).height(windowheight);
		}
	});

}

function captionSliding(){
	$('.Carousel .line').each(function(){
		var lineheight = $(this).children('.text').innerHeight();
		var linkheight = $(this).children('.link').innerHeight();
		var lineheightTotal = $(this).innerHeight() - lineheight;
		var linkBottom = lineheightTotal-linkheight;

		$(this).children('.link').css('bottom', lineheightTotal).show();

		$(this).hover(function(){
			$('.link', this).stop().animate({bottom: linkBottom}, {queue:false, duration:160});
		}, function() {
			$('.link', this).stop().animate({bottom: lineheightTotal}, {queue:false, duration:160});
		});
	});
}

function setCasoEstudo(index) {
	$('#casos_estudo_flash').externalInterface({
		method:'asFunc',
		args:index
	});
}

function setPortfolio(index) {
	$('#portfolio_flash').externalInterface({
		method:'asFunc',
		args:index
	});
}

function getParameterByName( name )
{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return decodeURIComponent(results[1].replace(/\+/g, " "));
}
	
function popupNews(){
	    var newsID = getParameterByName("newsid");
	
		if(newsID){
			//alert(newsID);
			Shadowbox.open({
				content:    'newsList.html?id='+newsID,
				player:     "iframe",
				height:     435,
				width:      990
			});
		}
}

$(document).ready(function(){

// TABS CONTAINER
	$("#Tabs .detail").hide();
	$("#Tabs .tabs_nav li:first").addClass("active").show();
	$("#Tabs .detail:first").show();

	$("#Tabs .tabs_nav li").click(function() {
		$("#Tabs .tabs_nav li").removeClass("active");
		$(this).addClass("active");
		$("#Tabs .detail").hide();
		var activeTab = $(this).find("a").attr("href");
		$(activeTab).show();
		return false;
	});
		
	// COLUMNS EQUAL HEIGHT
	setEqualHeight($('.News ul > .column'));
	
	$('.nav .home').hide();

			
	// ANCHOR NAVIGATION + ACTIVATE OPTION MENU
	if($('a.anchorlink').length > 0){
		$('a.anchorlink').anchorAnimate();
	}
	
	// ACTIVATE TOP ANCHOR FOR IE6
	if($.browser.msie && $.browser.version.substr(0, 1) < 7){
		if($('a.anchor').length > 0){
			$('a.anchor').removeClass('hidden').anchorAnimate();
		}
	}

	// DETECT HEIGHT CONTENT
	//setHgthCtntAndRpstMenu();
	
	
	// SLIDING BOXES
	captionSliding();
	
	$('.HeightContent').bind('inview', function (event, visible) {  
		if (visible) {
			$("#" + $(this).attr("id") + "_nav").parent().addClass("current");
			if($(this).attr("id") == "Home"){
				$('.nav .home').fadeOut("slow");
			}
		}
		else {
			$("#" + $(this).attr("id") + "_nav").parent().removeClass("current");
			if($(this).attr("id") == "Home"){
				$('.nav .home').fadeIn("slow");
			}
		}
	});

	

});

Shadowbox.init({ overlayColor: '#fff', displayNav: false});

$(window).load(function(){
    popupNews();						  
});



$(window).resize(function(){
	// DETECT HEIGHT CONTENT
	//setHgthCtntAndRpstMenu();

});

