// JavaScript Document
/* ------------------------------------------------------------------------- */	
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */			
var WWWROOT = "http://www.elitist-productions.com/";

/* ------------------------------------------------------------------------- */
//Capturamos eventos CLICK en las opciones de menú:
/* ------------------------------------------------------------------------- */			
$(document).ready(function(){
	
	$('#home').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('1');
	});
	
	$('#bio').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('2');
	});
	
	$('#disco').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('3');
	});
	
	$('#gigs').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('4');
	});
	
	$('#downloads').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('5');
	});
	
	$('#mygallery').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('6');
	});
	
	$('#press').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('7');
	});	
	
	$('#contact').live('click', function(eve){
		eve.preventDefault();		
		MenuOptionSet('8');
	});	
	
	

	/* ------------------------------------------------------------------------- */	
	/*Handling events from clicking the headlines on the left*/
	/* ------------------------------------------------------------------------- */	
 
	$('.hd_on_the_left').live('click', function(eve){
			eve.preventDefault();			
			element = eve.target;
			url = $(element).attr('title');
			//console.log ($(element).attr('title'));
			
			$.ajax({
				type: "POST",
				url: url,
				dataType: 'html',
				success: function(data) { 		
					var dom = data;								
					var htmlToInsert = $('div#estructura',$(dom)).html();		
					$('#estructura').remove();	
					$('#estructura_gancho').append("<div id='estructura'> </div>");
					$('#estructura').html(htmlToInsert);				
					//console.log('HTML FINAL: '+$('html').html());													
				} 
			});		
		});
		
	/* ------------------------------------------------------------------------- */	
	/* Submitting the Contact Form via Ajax*/
	/* ------------------------------------------------------------------------- */	
	$('#contactSubmit').live('click',function(eve){
		eve.preventDefault();		
		//console.log('clicking sumbit button');
		
		var my_name = $('#name').val();
		var my_email = $('#email').val();
		var my_subject = $('#subject').val();
		var my_message = $('#message').val();	
		//console.log(my_name+' - '+my_email+' - '+my_subject+' - '+my_message);		
		
		var contactUrl = WWWROOT+"index.php/contact/send";			
		$.post(contactUrl, {
		name:my_name, email:my_email, subject:my_subject, message:my_message}, function(data){
			var dom = data;								
			var htmlToInsert = $('div#estructura',$(dom)).html();		
			$('#estructura').remove();	
			$('#estructura_gancho').append("<div id='estructura'> </div>");
			$('#estructura').html(htmlToInsert);				
			//console.log('HTML FINAL: '+$('html').html());		
			
			activarScrollPane();
		});
		
		
	});
	
	$('#myContactForm').submit(function(eve){
		eve.preventDefault();		
		console.log('process me');	
		
	});
	
	/* ------------------------------------------------------------------------- */	
	/*Handling events from clicking the Home link when sending a contact form 
	success or fails*/
	/* ------------------------------------------------------------------------- */		
	//SUCCESS
	$('#contactSuccess').live('click', function(eve){
		eve.preventDefault();		
		var strUrl = WWWROOT+"index.php/home";		
		//console.log("URL: "+strUrl);
		$.ajax({
			type: "POST",
			url: strUrl,
			dataType: 'html',
			success: function(data) { 		
				var dom = data;			
				var htmlToInsert = $('div#estructura',$(dom)).html();		
				$('#estructura').remove();	
				$('#estructura_gancho').append("<div id='estructura'> </div>");
				$('#estructura').html(htmlToInsert);				
				//console.log('HTML FINAL: '+$('html').html());					
				
				activarScrollPane();
			} 
		});		
	});	
	//FAIL	
	$('#contactFail').live('click', function(eve){
		eve.preventDefault();		
		var strUrl = WWWROOT+"index.php/home";		
		//console.log("URL: "+strUrl);
		$.ajax({
			type: "POST",
			url: strUrl,
			dataType: 'html',
			success: function(data) { 		
				var dom = data;			
				var htmlToInsert = $('div#estructura',$(dom)).html();		
				$('#estructura').remove();	
				$('#estructura_gancho').append("<div id='estructura'> </div>");
				$('#estructura').html(htmlToInsert);				
				//console.log('HTML FINAL: '+$('html').html());					
				
				activarScrollPane();
			} 
		});		
	});	
});

$(document).ready(
	function()
	{
		//$('#subcontenido_scrollbar').jScrollPane();
		$('.scroll-pane').jScrollPane(
			{
			showArrows: false,
			horizontalGutter: 30,
			verticalGutter: 10
			}
		);
	}
);

function activarScrollPane(){
	$('.scroll-pane').jScrollPane(
		{
		showArrows: false,
		horizontalGutter: 30,
		verticalGutter: 10
		}
	);
}

function MenuOptionSet(val){	
	
	var section;
	switch (val){
		case '1':
			section = 'home';
			break;
		case '2':
			section = 'biography';
			break;
		case '3':
			section = 'discography';
			break;
		case '4':
			section = 'gigs';
			break;
		case '5':
			section = 'downloads';
			break;
		case '6':
			section = 'gallery';
			break;
		case '7':
			section = 'press';
			break;
		case '8':
			section = 'contact';
			break;
		
		default:
			section = 'home';
	}       
	
	var strUrl = WWWROOT+"index.php/"+section;		
	//console.log("URL: "+strUrl);

	$.ajax({
		type: "POST",
		url: strUrl,
		dataType: 'html',
		success: function(data) { 		
			var dom = data;			
			var htmlToInsert = $('div#estructura',$(dom)).html();		
			$('#estructura').remove();	
			$('#estructura_gancho').append("<div id='estructura'> </div>");
			$('#estructura').html(htmlToInsert);				
			//console.log('HTML FINAL: '+$('html').html());					
			
			activarScrollPane();
		} 
	});		
}


/* ------------------------------------------------------------------------- */	
/*This function is called from Downloads section when clicking [Tracklist]*/
/* ------------------------------------------------------------------------- */	
function showPopup(id, title) {    	
	var tracklist_title = "Tracklist :: "+title;
	$("#dialog_tracklist" + id).dialog({
		autoOpen: false, 
		bgiframe: true,
		modal: true,
		resizable: false,
		draggable: false,
		width: 'auto',
		height: 'auto',
		title: tracklist_title,
		position: [520, 150]
	});
	$("#dialog_tracklist" + id).dialog('open');       
}

/* ------------------------------------------------------------------------- */	
/*This function is called from Gallery (view_content_gallery) section when 
clicking a gallery (title)*/
/* ------------------------------------------------------------------------- */	


function showGalleryPopup(id, title) {    	
	
	var gallery_title = "Gallery :: "+title;
	$("#dialog_gallery" + id).dialog({
		autoOpen: false, 
		bgiframe: true,
		modal: true,
		resizable: true,
		draggable: true,
		width: 'auto',
		height: 'auto',
		//width:'800px',
		//height:'600px',
		//position: [520, 150],
		title: gallery_title
		
	});
	//$("#dialog_gallery" + id).dialog('open');       
	//showGallery(id);
	
	var d = $("#dialog_gallery" + id).html('<iframe style="width:750px; height:800px;" id="ifrm'+id+'"></iframe>');
	d.dialog('open');
	var url="http://www.elitist-productions.com/img/gallery/galleryview/"+id+"/index.html";
	$("#dialog_gallery" + id +">#ifrm"+id+"").attr("src", url);
}


/*
function showGallery(id) {    		
	$("#photos"+id).galleryView({
		panel_width: 800,
		panel_height: 300,
		frame_width: 100,
		frame_height: 100
	});	
}
*/

/*
//Esta funcion es llamada desde el menu view_header.php
//Cada vez que el estado readyState cambia, se ejecuta 
//la siguiente funcion handleHPTabResponse
var req = new XMLHttpRequest();
function handleHPTabResponse()  
{         
        
        if(req.readyState == 4)
        { 
            var response = req.responseText; 
			alert ("RESPONSE: "+response);
            document.getElementById('contenido').innerHTML=response;	       
        //    document.getElementById('divloadprocess').style.display='none';
		//	 document.getElementById('PIXALERT').style.display="block";
       } 
        else if(req.readyState != 4)
        {
          // document.getElementById('divloadprocess').style.display='';
        }
}
*/

/* ------------------------------------------------------------------------- */	
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
