

/************************** VARS DECLARATION ******************************/


var pageName = 'servicios';

var pageTitle = 'servicios';

var subSectionActive = '';

var subitemImageActive = 0;

var workActive = false;

var switching_delay = 4000;

var high_delay = 300;

var medium_delay = 500;

var slow_delay = 1000;

var initload_delay = 2000;

var lang = 'es';

var documentRoot = "http://luzpublicidad.com/";

var menuES = '<a href="javascript:void(0);" onclick="changeContent(\'servicios\', \'servicios\');" class="menu_item" id="menuitem_servicios">SERVICIOS</a><span class="menu_separator">|</span><a href="javascript:void(0);" onclick="changeContent(\'conocer\', \'conocer\');" class="menu_item" id="menuitem_conocer">CONOCER</a><span class="menu_separator">|</span><a href="javascript:void(0);" onclick="changeContent(\'contacto\', \'contacto\');" class="menu_item" id="menuitem_contacto">CONTACTO</a>';

var menuEN = '<a href="javascript:void(0);" onclick="changeContent(\'servicios\', \'services\');" class="menu_item" id="menuitem_servicios">SERVICES</a><span class="menu_separator">|</span><a href="javascript:void(0);" onclick="changeContent(\'conocer\', \'acquaintance \');" class="menu_item" id="menuitem_conocer">ACQUAINTANCE </a><span class="menu_separator">|</span><a href="javascript:void(0);" onclick="changeContent(\'contacto\', \'contact\');" class="menu_item" id="menuitem_contacto">CONTACT</a>';

var footerES = '2010 &copy; LUZ PUBLICIDAD, S.&nbsp;L. | TODOS LOS DERECHOS RESERVADOS | <a href="javascript:void(0);" onclick="showLegal();">AVISO LEGAL</a> |';

var footerEN = '2010 &copy; LUZ PUBLICIDAD, S.&nbsp;L. | ALL RIGHTS RESERVED | <a href="javascript:void(0);" onclick="showLegal();">LEGAL ADVICE/WARNING</a> |';

var subfooterES = '<span id="close_work_button"><a href="javascript:void(0);" onclick="closeWork(false);">CERRAR Y VOLVER</a></span><span id="view_thumbs_message">(VER MINIATURAS -->)</span>';

var subfooterEN = '<span id="close_work_button"><a href="javascript:void(0);" onclick="closeWork(false);">CLOSE AND BACK</a></span><span id="view_thumbs_message">(VIEW THUMBNAILS-->)</span>';


/************************** MAIN EVENT HANDLERS ******************************/


$(document).ready(function(){		
	
	$('#image_loading').fadeOut(initload_delay, 
		
		function(){
			
			var blackBarWidth = $('#black_bar').width() + 'px';

			$("#work_loader").fadeIn(high_delay);

			$('#black_bar_content').css('display', 'none');

			$('#black_bar').css('width', '1px');

			$('#black_bar').animate({opacity: 1}, 0);

			$('#black_bar').css('filter',"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + documentRoot + "resources/images/background_black_clarita.png', sizingMethod='crop')");
			
			$('#loading_content').css('display', 'none');

			$('#loading').animate({height: 1}, medium_delay, 
				
				function(){ 
				
					$('#bg_grid').animate({height: $(window).height()}, medium_delay, 
						
						function(){ 
							
							$('#black_bar').animate({width: blackBarWidth}, medium_delay, "swing", 
								
								function(){ 
									
									$('#black_bar_content').fadeIn(slow_delay); 

									$("#work_loader").fadeOut(high_delay);
								
								}); 
							
						}); 
						
				});
			
			setupPageData(pageTitle);

			$('#content_menu').html((lang == 'es') ? menuES : menuEN );

			$('#menuitem_' + pageName).addClass('active');

			$('#footer').html((lang == 'es') ? footerES : footerEN );

			$('#sub_description_footer').html((lang == 'es') ? subfooterES : subfooterEN );

			$('#content').load('resources/content/' + lang + '/maincontent.html #c_' + pageName, 
				
				function(){ 
					
					$('#c_' + pageName).fadeIn(slow_delay); 
					
				});
		
		});

});	


function hideBar(callbackfunction){
	
	$('#black_bar_content').fadeOut(high_delay, 
		
		function(){
			
			var blackBarWidth = $('#black_bar').width() + 'px';

			$('#black_bar').animate({width: 0}, medium_delay, "swing",
				
				function(){
					
					$('#black_bar').css('width', blackBarWidth);

					$('#black_bar').animate({opacity: 0}, 0, 
						
						function(){ 
							
							if(callbackfunction != undefined) callbackfunction(); 
							
						});
				
				});

		});
		
}


function showBar(callbackfunction){

	$('#black_bar_content').fadeIn(0,
		
		function(){ 
			
			var blackBarWidth = $('#black_bar').width() + 'px';

			$('#black_bar_header').css('display','none');

			$('#menu a').each( 
				
				function(i){ 
						
					$(this).removeClass('active'); 
				
				});

			$('#menuitem_' + pageName).addClass('active');	

			$('#c_' + pageName).fadeOut(0);

			$('#black_bar').css('width', '1px');

			$('#black_bar_content').fadeOut(0);	

			$('#black_bar').animate({opacity:1}, 0, "swing", 
										
				function(){
					
					$('#black_bar_header').css('display', 'block');

					$('#black_bar').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + documentRoot + "resources/images/background_black_clarita.png', sizingMethod='crop')");
					
					$('#black_bar').animate({width: blackBarWidth}, slow_delay, "swing", 
						
						function(){ 
						
							$('#black_bar_content').fadeIn(slow_delay, 
								
								function(){ 
									
									if(callbackfunction != undefined) callbackfunction(); 
									
								}); 
								
						}); 
				
				});

		});
		
}


function changeContent(newPageName, newPageTitle, auxfunction){

	pageName = newPageName;

	pageTitle = newPageTitle;

	hideBar(

		function(){			
			
			cleanPageData();

			$("#work_loader").fadeIn(high_delay);
			
			$('#content').html('');

			$('#content').css('display', 'none');
			
			if (auxfunction != undefined) auxfunction(); 

			showBar(

				function(){				

					setupPageData(pageTitle);

					$('#content').load('resources/content/' + lang + '/maincontent.html #c_' + pageName, 
						
						function(){

							$('#content').fadeIn(slow_delay, 
						
								function(){
									
									$("#work_loader").fadeOut(high_delay);
							
								});
						
						});

				});
			
		});

}


function changeLanguageSection(newlang){
	
	lang = newlang;
	
	switch(pageName){
		
		case 'aviso_legal': pageTitle = (lang == 'es') ? 'aviso legal' : 'legal advice/warning'; break;
		
		case 'conocer': pageTitle = (lang == 'es') ? 'conocer' : 'acquaintance '; break;
		
		case 'contacto': pageTitle = (lang == 'es') ? 'contacto' : 'contact'; break;
		
		default: pageTitle = (lang == 'es') ? 'servicios' : 'services'; 	//'servicios'
	
	}
	
	$('#content_menu').fadeOut(high_delay);

	$('#footer').fadeOut(high_delay);

	hideSocialMessage();

	changeContent(pageName, pageTitle, 
		
		function(){
			
			$('#content_menu').html((lang == 'es') ? menuES : menuEN );

			$('#content_menu').fadeIn(high_delay);
			
			$('#footer').html((lang == 'es') ? footerES : footerEN );				

			$('#footer').fadeIn(high_delay);

			$('#sub_description_footer').html((lang == 'es') ? subfooterES : subfooterEN );
	
		});

}


function openWork(subsection){
	
	workActive = true;

	subSectionActive = subsection;

	subitemImageActive = 1;
	
	$("#work_loader").fadeIn(high_delay);

	var workContainerWidth = $('#work').width() + 'px';	

	hideBar(
		
		function(){	
			
			$('#content').html('');

			$('#content').css('display', 'none');

			$('#bg_grid').animate({ height: '0' }, medium_delay, 
				
				function(){ 
					
					$('#work').css('width', '0');
			
					$('#work').css('display', 'block');

					$('#work').animate({opacity: 1}, 0);
					
					$('#bg_grid').animate({height: $(window).height()}, medium_delay, 
						
						function(){

							$('#work').animate({width: workContainerWidth}, medium_delay, "swing", 
						
								function(){

									$('#sub_description_container').fadeIn(slow_delay, 
												
										function(){

											$('#sub_description_content').load('resources/content/' + lang + '/descripciones.html #d_' + subSectionActive, 
												
												function(){

													$('#sub_description_' + subSectionActive + '_' + subitemImageActive).fadeIn(high_delay);
											
												});
									
										});
									
									$('#sub_images_container').load('resources/content/images/' + subSectionActive + '.html', 
										
										function(){

											$('#s_' + subSectionActive).fadeIn(slow_delay); 

											$('#c_' + pageName).css('display', 'none');

											$('#sub_thumbs_container').load('resources/content/miniaturas/' + subSectionActive + '.html', 
												
												function(){											

													$('#sub_thumbs_' + subSectionActive).css('display', 'block');

													$('#subitem_' + subSectionActive + '_' + subitemImageActive).fadeIn(slow_delay, 'swing', 
														
														function(){

															$('#sub_logo_container').fadeIn(high_delay); 

															$("#work_loader").fadeOut(medium_delay);

															setTimeout("nextWork();", switching_delay);

														}); 

												});

										});

								});
						
						});

				});

		});
			
}


function closeWork(viewLegal){
	
	if(viewLegal){
		
		pageName = 'aviso_legal';

		pageTitle = (lang == 'es') ? 'aviso legal' : 'legal advice/warning';

	}
	
	cleanPageData();

	workActive = false;

	$("#work_loader").fadeIn(high_delay);

	$('#work').fadeOut(slow_delay,
		
		function(){

			$('#sub_description_container').fadeOut(high_delay);

			$('#s_' + subSectionActive).fadeOut(high_delay);

			$('#sub_thumbs_' + subSectionActive).fadeOut(high_delay); 
			
			$('#content').html('');

			$('#content').css('display', 'none');

			$('#bg_grid').animate({ height: '0' }, medium_delay, 
				
				function(){

					$('#bg_grid').animate({height: $(window).height()}, medium_delay, 
						
						function(){

							showBar(

								function(){	

									setupPageData(pageTitle);
									
									$('#content').load('resources/content/' + lang + '/maincontent.html #c_' + pageName);

									$('#content').fadeIn(medium_delay, 
						
										function(){
											
											$("#work_loader").fadeOut(high_delay);
											
											$('#s_' + subSectionActive).css('display', 'none');

											$('#sub_thumbs_' + subSectionActive).css('display', 'none');
											
											$('#sub_logo_container').css('display', 'none');

											$('#sub_description_content').html('');
											
											$('#sub_description_container').css('display', 'none');

											$('#s_' + subSectionActive + ' img').each( function(i){ $(this).css('display', 'none'); });

											subSectionActive = '';

											if(typeof(timer) != "undefined"){ clearTimeout(timer); }

										});				

								});
						
						});
				
				});

		});

}


function showThumbs(){

	$('#sub_thumbs_' + subSectionActive).css('visibility', 'visible');

}


function hideThumbs(){

	$('#sub_thumbs_' + subSectionActive).css('visibility', 'hidden');

}


function prevWork(){

	changeWorkImage(subitemImageActive-1);

}


function nextWork(){

	changeWorkImage(subitemImageActive+1);

}


function changeWorkImage(item){
	
	var total_images = $('#s_' + subSectionActive + ' img').size();

	if(typeof(timer) != "undefined"){ clearTimeout(timer); }

	timer = setInterval("nextWork()", switching_delay);

	if(item > total_images){
		
		item = 1;

	}

	if(item == 0){
		
		item = total_images;

	}

	oldSubitemImageActive = subitemImageActive;

	subitemImageActive = item;
	
	if(oldSubitemImageActive != subitemImageActive){
		
		$('#sub_description_' + subSectionActive + '_' + oldSubitemImageActive).fadeOut(slow_delay, 'swing', 
			
			function(){ 
				
				$('#sub_description_' + subSectionActive + '_' + subitemImageActive).fadeIn(slow_delay); 
				
			});											

		$('#subitem_' + subSectionActive + '_' + oldSubitemImageActive).fadeOut(slow_delay, 'swing', 
			
			function(){ 
				
				$('#subitem_' + subSectionActive + '_' + subitemImageActive).fadeIn(slow_delay); 
				
			});

	}

}


function showSocialMessage(typeMessage){

	var message;

	if(typeMessage == 'linkedin'){
			
		if(lang == 'en'){
		
			message = 'Visit <a href="http://es.linkedin.com/pub/paloma-luzarraga-ormaechea/21/a16/4b9" target="_blank">my LinkedIn\'s professional profile</a>';

		}else{
		
			message = 'Visita <a href="http://es.linkedin.com/pub/paloma-luzarraga-ormaechea/21/a16/4b9" target="_blank">mi perfil profesional</a> en LinkedIn';

		}
	
	}else{	// typeMessage == 'skype'
			
		if(lang == 'en'){

			message = 'My Skype user: <b>pluzarraga1</b>';

		}else{

			message = 'Mi usuario Skype: <b>pluzarraga1</b>';
		
		}			
				
	}
	
	$('#social_message').html('<p style="text-align: center; color: #FFFFFF;">' + message + '&nbsp;&nbsp;&nbsp;[&nbsp;<a href="javascript:void(0);" onclick="hideSocialMessage()">x</a>&nbsp;]</p>');

	$('#social_message').css('visibility', 'visible');

}

function hideSocialMessage(){

	$('#social_message').css('visibility', 'hidden');

	$('#social_message').html('');

}


function cleanPageData(){
	
	$('#content_title').html('');

	$('#black_bar_header').html('');

}


function setupPageData(pageTitle){

	$('#content_title').html(pageTitle);

	$('#black_bar_header').html(pageTitle);

	document.title = 'Luz Publicidad | ' + pageTitle;

}


function loadHomeSection(){

	 changeContent('servicios', (lang == 'es') ? 'servicios' : 'services');

}


function showLegal(){
	
	if(workActive){

		closeWork(true);

	}else{
	
		changeContent('aviso_legal', (lang == 'es') ? 'aviso legal' : 'legal advice/warning');

	}

}


/************************** AUX FUNCTIONS  ******************************/


function ucWords(string){

	var arrayWords;

	var returnString = "";

	var len;

	arrayWords = string.split(" ");

	len = arrayWords.length;

	for(i=0;i<len;i++){

		returnString = returnString + ucFirst(arrayWords[i]) + ((i != (len-1)) ? " " : "");
	}

	return returnString;

}


function ucFirst(string){

	return string.substr(0, 1).toUpperCase() + string.substr(1, string.length).toLowerCase();

}
