/**
	Projeto - Site Tampćo (b!ferraz) v: 0.1
	Developer(s):
		+ Fernando Basilio (fernando.basilio@rede.ag)
*/

/* clientes */

function insertBG(){
	$(".lista_clientes").append("<div class='bg_clientes'></div>");
	$(".bg_clientes").css({opacity: 0});
	$(".bg_clientes").animate({
			opacity: 0.80
		}, 500
	);	
}

function removeBG(){
	$(".bg_clientes").animate({
			opacity: 0
		}, 300, function(){
			$(this).remove();					
		}
	);				
}

function initClientes(){

	$(".lista_clientes .item_clientes").bind("mouseenter",function(){
		
		insertBG();
		
		$(this).clone().appendTo(".lista_clientes").addClass("clone");
		
		var obj = $(this);
		var x = $(obj).position().left;
		var y = $(obj).position().top;

		/*
		console.log(x);
		console.log(y);

		var _html = '<div class="item_clientes_content">';
		_html += '<h3><a href="' + url + '" rel="bookmark" title="' + title + '">' + title + '</a></h3>';
		_html += desc;
		_html += '<a href="' + url + '" class="ico_mais rpc">+</a>';
		_html += '</div>';

		<div class="item_clientes_content">
		<h3><a href="#" rel="bookmark" title="' + title + '">' + title + '</a></h3>
		<p>desc</p>
		<a href="#" class="ico_mais rpc">+</a>
		</div>
		*/
		
		Cufon.replace('.clone p', { fontFamily: 'Calvert MT Std Light' });
		Cufon.replace('.clone h3', { fontFamily: 'Calvert MT Std' });
		
		$(".clone").css({
			position: "absolute",
			top: y,
			left: x,
			zIndex: "99991"
		})				
		
		if(x >= 575){

			if(x == 575){
				lPosition = 345;
			}else if(x == 690){
				lPosition = 460;
			}
			
			$(".clone").animate({
					width: "345px",
					left: lPosition+"px"
				}, {
					duration: 500,
					queue: false
				}
			)

		}else{
		
			$(".clone").animate({
					width: "345px"
				}, {
					duration: 500,
					queue: false
				}
			)
			
		}
		
		$(".clone").bind("mouseleave",function(){
			$(this).animate({
					width: "115px",
					left: x+"px",
					opacity: 0
				}, 300, function(){
					removeBG();
					$(this).remove();
				}
			);
		});
		
	});

}


// copyHeight
function copyHeight(obj){
	hMax = $(obj).eq(0).height();
	for (i=0; i<$(obj).length; i++){
		if(hMax < $(obj).eq(i).height()){
			hMax = $(obj).eq(i).height();
		}
	}
	$(obj).height(hMax);
}


// centralizeElement
function centralizeElement(obj){
	var obj = obj;
	if ($("body").height() > $(obj).height()) {
		$(obj).css({top: '50%', marginTop: -($(obj).height()/2) + 'px'});
	}else {
		$(obj).css({marginTop: '0px', top: '0px'});
	}
	if ($("body").width() > $(obj).width()) {
		$(obj).css({left: '50%', marginLeft: -($(obj).width()/2) + 'px'});
	}else {
		$(obj).css({marginLeft: '0px', left: '0px'});
	}
}


// Return GET params
function returnParam(url,paramName){
	for(var qs = url.split("&"), i=0; i < qs.length; i++)
		if(qs[i].indexOf(paramName)>=0)
			return qs[i].split("=")[1];
	return false;
}


// Flash Calls
function openLink(url) {
	if(!url.match('http')) {
		switch(url) {
			case "example": window.location = 'http://www.example.com.br/'; break;
			case "exampl2": doSomething(); return true; break;
			default: return false;
		}
	}else
		window.location = url;
	return true;
}



// Popup handler
function openPopup(u,n,w,h,o,c) {
	var l = t = 18;
	if (c) {
		l = (screen.availWidth-w) / 2;
		t = (screen.availHeight-h) / 2;
	}
	p=window.open(u,'pop_'+n,'left='+l+',top='+t+',width='+w+',height='+h+''+((o)?','+o:''));
}

function comunicadoPop(url){
	openPopup(url,'Comunicado',415,350,'scrollbars=1',true);
}
