﻿$(document).ready(function() {    
    /*alert($("#derindex").width());
    $("#derindex").width("380");*/
       //Speed of the slideshow
	var speed = 5000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').height($('#slider').height());	
	$('#gallery').height($('#slider').height() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #mask-excerpt, #excerpt li,#mask-snombres,#snombres li').width($('#slider').width());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);	
	
	$('#gallery li:first, #excerpt li:first,#snombres li:first').addClass('selected');

	//Pause the slidershow with clearInterval
	$('#btn-pause').click(function () {
		$(this).hide();
		$('#btn-play').show();
		//alert("pause");
		clearInterval(run);		
		return false;
	});

	//Continue the slideshow with setInterval
	$('#btn-play').click(function () {
		run = setInterval('newsscoller(0)', speed);	
		//alert("play");
		$(this).hide();
		$('#btn-pause').show();
		return false;
	});
	
	//Next Slide by calling the function
	$('#btn-next').click(function () {
		newsscoller(0);	
		return false;
	});	

	//Previous slide by passing prev=1
	$('#btn-prev').click(function () {
		newsscoller(1);	
		return false;
	});	
	
	//Mouse over, pause it, on mouse out, resume the slider show
	$('#slider').hover(
	
		function() {
			clearInterval(run);
		}, 
		function() {
			run = setInterval('newsscoller(0)', speed);	
		}
	);
	    $("#mainmenu li>a").click(function(e){
	        //alert("llega");
	        //e.preventDefault();
	        //$("#mainmenu li>a").
	       // $("#mainmenu li>a").find("a"
//	        var act=$(this).attr("class");
//	        alert(act);
//	        $(this).addClass(act+" "+act+"a");
//	        alert($(this).attr("class"));
	    }); 	
	 	
	 	
	 	
	 	
	 	$("#scrollable").scrollable({items:'.items',horizontal:true});
	 	$("#scrolltravesti").scrollable({items:'.items',horizontal:true});
	 	$("#scrollchico").scrollable({items:'.items',horizontal:true});
	 	
	 	//Cargar Provincias y Ciudades
	 	//alert("hoal");
	 	
	 	$(".bprovincia").click(function(e){
	 	    if($(".bprovincia option").length==1){
	 	        $(this).attr("disabled","disabled");
	 	        $("#lp").css("display","inline");
	 	        $.ajax({
	 	            type:"POST",          
                    dataType:"html",
	 	            url:"autenticacion/calls/provinciacity.ashx",
	 	            data:"tarea=provincia",
	 	            success:function(msg){
	 	                $("#lp").hide();
	 	                $(".bprovincia").empty().append("<option value=' '>- Elija Provincia -</option>").append(msg);
	 	                $(".bprovincia").removeAttr("disabled");
	 	            }
	 	        });
	 	    }
	 	});
	 	$(".bprovincia").change(function(e){
	 	    var idp=$(this).val();	 	        	 	        
	 	        //alert("->"+$(this).val()+"<-");
	 	        if($(this).val()!=" "){
	 	            $("#lc").css("display","inline");
	 	            $(".bciudad").attr("disabled","disabled");
	 	            $.ajax({
	 	                type:"POST",          
                        dataType:"html",
	 	                url:"autenticacion/calls/provinciacity.ashx",
	 	                data:"idprovincia="+idp+"&tarea=ciudad",
	 	                success:function(msg){
	 	                    $("#lc").hide();
	 	                    $(".bciudad").removeAttr("disabled");
	 	                    $(".bciudad").empty().append("<option value=' '>- Elija Ciudad -</option>").append(msg);
	 	                }
	 	            });
	 	        }else{
	 	            $(".bciudad").empty().append("<option value=' '>- Elija Ciudad -</option>")
	 	        }
	 	});
	 	$(".bciudad").attr("disabled","disabled");
    });//==========FIN JQUERY
	
	function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');
	var current_nombre=$('#snombres li.selected').length ? $('#snombres li.selected'):$('#snombres li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
		var next_nombre=(current_nombre.prev().length) ? current_nombre.prev() : $('#snombres li:last');
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
		var next_nombre=(current_nombre.next().length) ? current_nombre.next() : $('#snombres li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li,#snombres li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');
	next_nombre.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	$('#mask-snombres').scrollTo(next_nombre,800);
}