/**
* TWSAINT - TETRAWARE INFOGRAFICA S.C.A. 2010
* tetraware <tetraware@tetraware.net>
*/

$(function(){
	// menu
	var menu_css = ['parent-hover', 'child-hover1', 'child-hover2', 'child-hover3', 'child-hover4'];
	$('ul.mainmenu').dropDownMenu({timer: 800, levels: menu_css});
	
	// toggle
	$("dl.toggle").each(function(){
		var $toogle_dt = $(this).children("dt");
		$toogle_dt.click(function(){
			$(this).toggleClass("current");
			$(this).next("dd").toggleClass("current");
			$(this).next("dd").toggle();
		});
		// crear otro boton para desplegar el toggle
		var rel_id	= $(this).attr('rel');
		var $rel	= $("#"+rel_id);
		if($rel){
			$rel.click(function(){
				$toogle_dt.click();
			});
		}
		
	});
	
	// colorbox
	//$("a[rel*='colorbox'],a[rel*='lightbox']").colorbox({transition:'elastic', speed:500, current: '{current}/{total}'});
	//$("a[rel*='colorbox-inline']").colorbox({inline:true, transition:'elastic', speed:500, current: '{current}/{total}'}); // , width: 660, height:400
	//$("a.iframe[rel*='colorbox']").colorbox({width:'60%', height:'60%', iframe:true});
	//
	//var colorbox_original_close = $.colorbox.close;
	//$.colorbox.close = function(){
		//$("#cboxOverlay").remove();
		//$("#colorbox").remove();
		//
		//colorbox_original_close();
		//$.colorbox.init();
	//};
	$("a[rel*='colorbox-inline']").colorbox({inline:true, transition:'elastic', speed:500, current: '{current}/{total}'}); // , width: 660, height:400
	$("a[rel*='colorbox']").colorbox({transition:'elastic', speed:500, current: '{current}/{total}'});	
	$("a[rel*='iframe-colorbox']").colorbox({width:'60%', height:'60%', iframe:true});
	$("a[rel*='enviara-colorbox']").colorbox({width:'500', height:'400', iframe:true});
	
	// tabs
	/*
	$("ul.tabs").tabs("div.tabs-panes > .pane", {
		api: true,
		effect: 'fade',
		history: true
	});
	$("#tabs[class!='notab']").tabs();
	*/
	
	$("div.tabs").tabs();
	
	// accord
	/*
	$("dl.acor").tabs("dl.acor dd", {
		tabs: 'dt',
		effect: 'slide',
		history: false,
		initialIndex: 0,
	});
	*/
 	$(".accordion").accordion({
 		header: 'div.acc-header' , 
 		autoHeight: false 
 	});
	/*
	// anything alider
	$(".anythingSlider").anythingSlider({
		easing: "swing",			// Anything other than "linear" or "swing" requires the easing plugin
        autoPlay: true,				// This turns off the entire FUNCTIONALY, not just if it starts running or not
        startStopped: false,		// If autoPlay is on, this can force it to start stopped
        delay: 3000,				// How long between slide transitions in AutoPlay mode
        animationTime: 400,			// How long the slide transition takes
        hashTags: false,			// Should links change the hashtag in the URL?
        buildNavigation: false,		// If true, builds and list of anchor links to link to each slide
        pauseOnHover: true,			// If true, and autoPlay is enabled, the show will pause on hover
        startText: "Iniciar",		// Start text
        stopText: "Parar",			// Stop text
        navigationFormatter: null	// Details at the top of the file on this use (advanced use)
	});
	*/
	// simple over
	$(".showhide").mouseenter(function(){
			//$(this).find("div").show("slow");
			$(this).find("span").toggleClass("current");
			$(this).find("div").show();
		}
		).mouseleave(function(){
			//$(this).find("div").hide("slow");
			$(this).find("span").toggleClass("current");
			$(this).find("div").hide();
		});
	//
	$(".showhide-rel").mouseenter(function(){
			var rel_id	= $(this).attr('rel');
			var $rel	= $("#"+rel_id);
			if($rel){
				$rel.toggleClass("current");
				$rel.show();
			}			
		}).mouseleave(function(){
			var rel_id	= $(this).attr('rel');
			var $rel	= $("#"+rel_id);
			if($rel){
				$rel.toggleClass("current");
				$rel.hide();
			}
		});
	
		
	// cycle para home
	$("#blqCategoriasHome div ul.shuffle").each(function(){
		// asignar la animacion
		//cy  = new Object();
		new $(this).cycle({ 
			fx: 'shuffle',
			shuffle:{ top: 145, left:5},
			speed:500
		});
		$(this).cycle('pause');
		// control de la animacion
		$(this).parent('div').mouseenter(function(){
			$(this).children('ul.shuffle').cycle('resume');
			$(this).children('ul.shuffle').cycle('next');
		}).mousemove(function(){
			$(this).children('ul.shuffle').cycle('resume');
		}).mouseleave(function(){
			$(this).children('ul.shuffle').cycle('pause');
		});
	});
	
	// simple over mor images
	$(".more-images").mouseenter(function(){
			$(this).find("div.more-images-info").show("slow");
		}
		).mouseleave(function(){
			$(this).find("div.more-images-info").hide();
		});	
	
	// datepicker
	$(".datepicker").each(function(){
		at_mindate = $(this).attr('mindate'); 
		at_maxdate = $(this).attr('maxdate'); 
		at_dateformat = $(this).attr('dateformat');
		//
		new $(this).datepicker({
				minDate: at_mindate,
				maxDate: at_maxdate,
				dateFormat: at_dateformat
		});
	});
	
	// tooltip
	//$("a[title]").tooltip();	
	$(".tooltip").tooltip();	
	
	// fancy thumb
	/*
	$("ul.thumb li").hover(
		function(){
			$(this).css({'z-index' : '10'});
			$(this).find('img').addClass("hover").stop().animate(
				{
					marginTop: '-25px',
					marginLeft: '-25px',
					top: '50%',
					left: '50%',
					width: '100px',
					height: '100px'
				},
				200
			);
		},
		function(){
			$(this).css({'z-index' : '0'});
			$(this).find('img').removeClass("hover").stop().animate(
				{
					marginTop: '0',
					marginLeft: '0',
					top: '0',
					left: '0',
					width: '50px',
					height: '40px'
				},
				400
			);
		}
	);	
	*/
	
	/* nivo slider */
	$('.slider').nivoSlider();
	
	/*imprimir pot id*/
	$(".print-intinerary").click(function(){
			var rel = $(this).attr('href');
			rel_html = "<html>"
				+"<head>"
				+"<style>.noforprint, img {display:none;} dt {font-size:18pt;} .titulo {font-size:24pt;} li {list-style:none;}</style>"
				+"</head>"
				+"<body>" 
				+$(rel).html()
				+ "</body>"
				+"</html>";
			//
			var ventimp = window.open(' ','popimpr');
			ventimp.document.write(rel_html);
			ventimp.document.close();
			//ventimp.print();
			//ventimp.close();
			//
			return false;
	});
	
	/* carrousel */
	/*$('div.[class^="carrousel"]').jCarouselLite({*/
	$('div.carrousel-serv').jCarouselLite({
		btnNext: ".next-serv",
		btnPrev: ".prev-serv",
		visible: 3,
		scroll: 1,
		speed: 500
	});	
	$('div.carrousel-otrosserv').jCarouselLite({
		btnNext: ".next-otrosserv",
		btnPrev: ".prev-otrosserv",
		visible: 6,
		scroll: 1,
		speed: 500
	});
	$('div.carrousel-webs').jCarouselLite({
		btnNext: ".next-webs",
		btnPrev: ".prev-webs",
		visible: 5,
		scroll: 1,
		speed: 500
	});

	$('div.carrousel-destacados').jCarouselLite({
		btnNext: ".next-destacados",
		btnPrev: ".prev-destacados",
		visible: 4,
		scroll: 1,
		speed: 800
	});
    $('#noticias-fotos').cycle({
        fx:     'scrollLeft', //'turnDown',
        speed:  '1000',
        timeout: 8000,
        pager:  '#noticias-fotos-nav',
		slideExpr: 'li',
	   // callback fn that creates a thumbnail to use as pager anchor 
		pagerAnchorBuilder: function(idx, slide) { 
			return '<a href="#"><span>&nbsp;</span></a>'; 
		} 		
    });	
	
});


$(document).ready(function(){
	// colorbox
	//$("a[rel*='colorbox'],a[rel*='lightbox']").colorbox({transition:'elastic', speed:500, current: '{current}/{total}'});
	//$("a[rel*='colorbox-inline']").colorbox({inline:true, transition:'elastic', speed:500, current: '{current}/{total}'}); // , width: 660, height:400
	//$("a.iframe[rel*='colorbox']").colorbox({width:'60%', height:'60%', iframe:true});
	//

});	

/*
function anythingslider_jump(idx){
	$('.anythingSlider').anythingSlider(idx);
}
*/

/*
// cycle para feedbacks
$('ul.feedbacks-anim').cycle({ 
	fx: 'scrollUp',
	pause: 1
});
// slideshow
$('.slideshow').cycle({
	fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
$('.slideshow2').cycle({
	fx: 'fade',
	next: '#next', 
	prev: '#prev' 		
});
*/

