// JavaScript Document
var currGallery = -1;
var currPos = 0;
var cWidth =[];

function initmidia(){
	
	currGallery = -1;
	
	$('#twittershare').click(function() {
		
		url = "http://www.vida-bela.com/" + "#" + $.address.value();
		//url = document.location.href.substr(0, document.location.href.indexOf('#')).toString() + "#" + $.address.value();
		url = encodeURIComponent(url);
		abreLinkPopUp('http://twitter.com/share?url=' + url + '&via=vidabelawear&text=Vida Bela',600,360);
		   
	});
	
	$('#facebookshare').click(function() {
		
		url = "http://www.vida-bela.com/" + "#" + $.address.value();
		//url = document.location.href.substr(0, document.location.href.indexOf('#')).toString() + "#" + $.address.value();
		url = encodeURIComponent(url);
		abreLinkPopUp('http://www.facebook.com/sharer.php?u=' + url + '&t=Vida Bela',500,360);
		   
    });

	$('.midia_rede').hover(
	
		function() {
			
			$(this).stop(true, true).animate({"backgroundColor": "#fbf2ef"}, timeOver);
			
		},
	
		function() {
			
			$(this).stop(true, true).animate({"backgroundColor": "#fdd2c4"}, timeOver);
			
		}
	
	);
	
	$('.midia_arrowL, .midia_arrowR').hover(
	
		function() {
			
			$(this).stop(true, true).animate({"opacity": .8}, timeOver);
			
		},
	
		function() {
			
			$(this).stop(true, true).animate({"opacity": 1}, timeOver);
			
		}
	
	);
	
	$('.midia_menuItem').hover(
	
		function() {
			
			if(currGallery!=$(this).attr("name")){
				
				$(this).children('.midia_menuItemseta').stop(true, true).animate({"left": "3"}, timeOver);
				$(this).stop(true, true).animate({"color": "#fff"}, timeOver);
				
			}
			
		},
	
		function() {
			
			if(currGallery!=$(this).attr("name")){
				
				$(this).children('.midia_menuItemseta').stop(true, true).animate({"left": "0"}, timeOver);
				$(this).stop(true, true).animate({"color": "#0193c2"}, timeOver);
				
			}
			
		}
	
	);
	
	changeGallery(0, 0);
	moveGalleryMidia(0, 0);
	
}

function setcWidth(value){
	
	cWidth.push(value);
	
}

function nextGalleryMidia(){
	
	var cpos = currPos - 300;
	cpos = (cpos<-(cWidth[currGallery]-725)) ? -(cWidth[currGallery]-725) : cpos;
	
	moveGalleryMidia(cpos, 1200);
	
}

function prevGalleryMidia(){
	
	var cpos = currPos + 300;
	cpos = (cpos>0) ? 0 : cpos;
	
	moveGalleryMidia(cpos, 1200);
	
}

function moveGalleryMidia(pos, time){
	
	$('#midia_imgContainer' + currGallery).animate({"left": pos}, {queue:false, duration: time, easing:"quartEaseInOut"});
	currPos = pos;
	
	setArrow(pos);
	
}

function changeGallery(id, time){
	
	if(currGallery!=id){
		
		if(currGallery!=-1){
			
			$('#midia_content' + id).css("width", "725px");
			$('#midia_content' + id).css("z-index", "9");
			
			$('#midia_content' + currGallery).css("z-index", "10");
			$('#midia_content' + currGallery).stop(true, true).animate({"width": 0}, time);
			
		}else{
			
			$('#midia_content' + id).css("width", "725px");
			$('#midia_content' + id).css("z-index", "11");
			
		}
		
		for (var i=0; i<cWidth.length; i++){
		
			if(i==id){
				
				$('#midia_menuItem' + i).stop().animate({"top" : 2, "fontSize" : "13px", "color": "#0193c2"}, 100);
				$('#midia_menuItem' + i).children('.midia_menuItemseta').stop().animate({"left": "3"}, 100);
				$('#midia_content' + i).fadeIn(0);
				
			}else{
				
				$('#midia_menuItem' + i).stop().animate({"top" : 5, "fontSize" : "11px", "color": "#0193c2"}, 100);
				$('#midia_menuItem' + i).children('.midia_menuItemseta').stop().animate({"left": "0"}, 100);
				$('#midia_content' + i).fadeOut(0);
				
			}
			
		}
		
		currGallery = id;
		moveGalleryMidia(0, 0);
		
	}
	
}

function setArrow(pos){
	
	if(pos<=-(cWidth[currGallery]-725)){
		
		$('.midia_arrowR').stop(true, true).fadeOut(500);
		
	}else{
		
		$('.midia_arrowR').stop(true, true).fadeIn(500);
		
	}
	
	if(pos>=0){
		
		$('.midia_arrowL').stop(true, true).fadeOut(500);
		
	}else{
		
		$('.midia_arrowL').stop(true, true).fadeIn(500);
		
	}
	
}
