var mySound;

Galleria.loadTheme('imagenes/themes/classic/galleria.classic.min.js');
soundManager.url = 'js/soundmanager/swf/'; // required: path to directory containing SM2 SWF files
soundManager.waitForWindowLoad = true;

$(document).ready(function() {
	
	$('#menu1 div.dropdown').hover(function(e) {
		$(this).find('div').show();
		$(this).find('div').css('visibility', 'visible');
	}, function(e) {
		$(this).find('div').hide();
		$(this).find('div').css('visibility', 'hidden');
	});
	
	$('#menu1 div.dropdown').find('div').width(function(index, width) {
		$(this).find('a').width($(this).parent().width()-14);
	});
	
	$('#menu2 div.dropdown').find('div').width(function(index, width) {
		$(this).find('a').width($(this).parent().width()-14);
	});
	
	$("#slider").easySlider({
		 auto: true
		,continuous: true
		,pause: 5000
		,prevText: ''
		,nextText: ''
	});
	
	$("#frases").dialog({
		 modal: true
		,draggable: false
		,resizable: false
		,autoOpen: false
		,width: 750
		,height: 550
		,buttons: {
			 'Musica': function() {
				mySound.togglePause();
			}
			,'Cerrar': function() {
				mySound.togglePause();
				$(this).dialog('close');
			}
		}
	});
	
	$('#slider a').click(function(e) {
		$("#frases").dialog('option', 'title', 'Frases');
		$("#frases").dialog('open');
		$.ajax({
			url: 'funciones/getFrases.php',
			dataType: 'json',
			success: function(response) {
				$('#frases').galleria({
					 width: 720
					,height: 430
					,imageTimeout: 3600000
					,autoplay: true
					,pauseOnInteraction: true
					,fullscreenDoubleTap: true
					,transition: 'fade'
					,dataSource: response
				});
				mySound.togglePause();
			}
		});
		return false;
	});
	
	if ( gup('s') ) {
		$.scrollTo('#menu2', 800);
	}
	
});

soundManager.onready(function(){
	mySound = soundManager.createSound({
		 id: 'frasesMP3'
		,url: 'js/soundmanager/Andrea Bocelli - Chiara.mp3'
	});
});

function gup( name ){
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp ( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return"";
	else
		return results[1];
}
