// Nivo Slider
$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:1500, //Slide transition speed
		pauseTime:5000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:false, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.9, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
});


// Carrousel Ofertas
$(window).load(function() {
        $(".carrousel").jCarouselLite({
            btnNext: ".next",
            btnPrev: ".prev",
            auto: 4800,
            speed: 1000
        });
    });
	
// abre y cierra panel de top y cambia imagen por cerrar y suscribete
$(document).ready(function(){
	// Expande Panel de Registro
	$("#open").click(function(){
		$("div#panel").slideDown("fast");
	
	});	
	
	// Cierra el panel de registro
	$("#close").click(function(){
		$("div#panel").slideUp("fast");	
	});		
	
	// cambia el link de cerrar a abrir
	$("#toggle_panel a").click(function () {
		$("#toggle_panel a").toggle();
	});	

});

// Busca subcategorias de productos
$(document).ready(function(){
	//Para cargar los modelos
	$("#subcategoria").change(function(){
		var filtro = $(this).val();
		$("#tipoArticulo").removeAttr("disabled");
		$.post("http://www.plazadelatecnologia.com/ajax/cargarModeloTipo",{filtro:filtro},function(data){
			sucess:				
				$("#tipoArticulo").empty().append(data);
				$("#tipoArticulo").removeAttr("disabled");
		});
		
	});
});
	
// Busca categorias por ciudad
$(document).ready(function(){
	//Para cargar los modelos
	$("#ciudad").change(function(){
		var filtro = $(this).val();
		$("#categoria").removeAttr("disabled");
		$.post("http://www.plazadelatecnologia.com/ajax/cargarModeloCiudad",{filtro:filtro},function(data){
			sucess:				
				$("#categoria").empty().append(data);
				$("#categoria").removeAttr("disabled");
		});
		
	});
});
	
// Busca categorias por subcategorias
$(document).ready(function(){
	//Para cargar los modelos
	$("#categoria").change(function(){
		var filtro = $(this).val();
		$("#subcategoria").removeAttr("disabled");
		$.post("http://www.plazadelatecnologia.com/ajax/cargarModelo",{filtro:filtro},function(data){
			sucess:				
				$("#subcategoria").empty().append(data);
				$("#subcategoria").removeAttr("disabled");
		});
		
	});
});

//Right Menu Accordion
jQuery.fn.initMenu = function() {  
    return this.each(function(){
        var theMenu = $(this).get(0);
        $('.acitem', this).hide();
        $('li.expand > .acitem', this).show();
        $('li.expand > .acitem', this).prev().addClass('active');
        $('li a', this).click(
            function(e) {
                e.stopImmediatePropagation();
                var theElement = $(this).next();
                var parent = this.parentNode.parentNode;
                if($(parent).hasClass('accordion')) {
                    if(theElement[0] === undefined) {
                        window.location.href = this.href;
                    }
                    $(theElement).slideToggle('normal', function() {
                        if ($(this).is(':visible')) {
                            $(this).prev().addClass('active');
                        }
                        else {
                            $(this).prev().removeClass('active');
                        }    
                    });
                    return false;
                }
                else {
                    if(theElement.hasClass('acitem') && theElement.is(':visible')) {
                        if($(parent).hasClass('collapsible')) {
                            $('.acitem:visible', parent).first().slideUp('normal', 
                            function() {
                                $(this).prev().removeClass('active');
                            }
                        );
                        return false;  
                    }
                    return false;
                }
                if(theElement.hasClass('acitem') && !theElement.is(':visible')) {         
                    $('.acitem:visible', parent).first().slideUp('normal', function() {
                        $(this).prev().removeClass('active');
                    });
                    theElement.slideDown('normal', function() {
                        $(this).prev().addClass('active');
                    });
                    return false;
                }
            }
        }
    );
});
};

$(document).ready(function() {$('.menuCategorias').initMenu();});


//Slider Home Plugin
;(function($) {
	$.fn.featureList = function(options) {
		var tabs	= $(this);
		var output	= $(options.output);

		new jQuery.featureList(tabs, output, options);

		return this;	
	};

	$.featureList = function(tabs, output, options) {
		function slide(nr) {
			if (typeof nr == "undefined") {
				nr = visible_item + 1;
				nr = nr >= total_items ? 0 : nr;
			}

			tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

			output.stop(true, true).filter(":visible").fadeOut();
			output.filter(":eq(" + nr + ")").fadeIn(function() {
				visible_item = nr;	
			});
		}

		var options			= options || {}; 
		var total_items		= tabs.length;
		var visible_item	= options.start_item || 0;

		options.pause_on_hover		= options.pause_on_hover		|| true;
		options.transition_interval	= options.transition_interval	|| 5000;

		output.hide().eq( visible_item ).show();
		tabs.eq( visible_item ).addClass('current');

		tabs.click(function() {
			if ($(this).hasClass('current')) {
				return false;	
			}

			slide( tabs.index( this) );
		});

		if (options.transition_interval > 0) {
			var timer = setInterval(function () {
				slide();
			}, options.transition_interval);

			if (options.pause_on_hover) {
				tabs.mouseenter(function() {
					clearInterval( timer );

				}).mouseleave(function() {
					clearInterval( timer );
					timer = setInterval(function () {
						slide();
					}, options.transition_interval);
				});
			}
		}
	};
})(jQuery);

//Script Slider Noticias
$(document).ready(function() {
	$.featureList(
		$("#tabsNoticias li a"),
		$("#output li"), {
			start_item	:	1
			}
		);
	$.featureList(
		$("#tabsNoticias_two li a"),
		$("#output_two li"), {
			start_item	:	1
			}
		);
	$.featureList(
		$("#tabsNoticias_three li a"),
		$("#output_three li"), {
			start_item	:	1
			}
		);
});

//Twitter
$(document).ready(function(){
        $(".tweet").tweet({
            username: "plazatecnologia",
            join_text: "auto",
            avatar_size: 32,
            count: 4,
            auto_join_text_default: "", 
            auto_join_text_ed: "Nosotros",
            auto_join_text_ing: "Estamos",
            auto_join_text_reply: "Comentamos",
            auto_join_text_url: "Buscando...",
            loading_text: "Cargando tweets...",
			template: function(i){return i["text"]}
        });
    });

//Tabulador Slider
$(document).ready(function()
{
	$(".tab_content").hide();
	$("ul.tabsSlider li:first").addClass("active").show();
	$(".tab_content:first").show();

	$("ul.tabsSlider li").click(function()
       {
		$("ul.tabsSlider li").removeClass("active");
		$(this).addClass("active");
		$(".tab_content").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});
});

//Tabulador videos
$(document).ready(function()
{
	$(".tab_videocontent").hide();
	$("ul.tabsSliderTwo li:first").addClass("activeVideo").show();
	$(".tab_videocontent:first").show();

	$("ul.tabsSliderTwo li").click(function()
       {
		$("ul.tabsSliderTwo li").removeClass("activeVideo");
		$(this).addClass("activeVideo");
		$(".tab_videocontent").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});
});

$(document).ready(function()
{
	$(".tabSocialmedia").hide();
	$("ul.tabsMedia li:first").addClass("activeSocial").show();
	$(".tabSocialmedia:first").show();

	$("ul.tabsMedia li").click(function()
       {
		$("ul.tabsMedia li").removeClass("activeSocial");
		$(this).addClass("activeSocial");
		$(".tabSocialmedia").hide();

		var activeTab = $(this).find("a").attr("href");
		$(activeTab).fadeIn();
		return false;
	});
});  

//List Style
$(document).ready(function(){
	$(".subMenu li:even").addClass("even-list");
	$(".subMenu li:odd").addClass("odd-list");
});

//Menu Sucursales Accordion
$(function () {
	$('.subMenu').each(function () {
		$(this).parent().eq(0).hoverIntent({
			timeout:0,
			over: function () {
				var current = $('.subMenu:eq(0)', this);
				current.slideDown(0);
			},
			out: function () {
				var current = $('.subMenu:eq(0)', this);
				current.fadeOut(200);
			}
		});
	});
	
});

//Form Focus
$(document).ready(function() {
			$('textarea').addClass("idleField");
			$('textarea').focus(function() {
				$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
			$('input[type="text"]').addClass("idleField");
       		$('input[type="text"]').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"]').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
			$('textarea').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		});	
		
// Efecto Expose
$(function() {
	// expose the form when it's clicked or cursor is focused
	var form = $(".expose").bind("click keydown", function() {
		$(this).expose({
			// when "unexposed", return to original background color
			onClose: function() {
				form.css({backgroundColor: null});
			}

		});
	});
});

//SocialBar Blogs
$(document).ready(function($) {
	var $floatingbox = $('#floating-box');
	
	if($('#content').length > 0){
	
		var bodyY = parseInt($('#content').offset().top) - 0;
		var originalX = $floatingbox.css('margin-left');
	
		$(window).scroll(function () { 
		  
			var scrollY = $(window).scrollTop();
			var isfixed = $floatingbox.css('position') == 'fixed';
			
			if($floatingbox.length > 0){
			
				if ( scrollY > bodyY && !isfixed ) {
					$floatingbox.stop().css({
						position: 'fixed',
						left: '50%',
						top: 0,
						marginLeft: -590
	
					});
				} else if ( scrollY < bodyY && isfixed ) {
					$floatingbox.css({
						position: 'relative',
						left: 0,
						top: -30,
						marginLeft: originalX
					});
				}
				
			}
	
		});
	}
});
