// JavaScript Document

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="newsfancy"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="images/fancybox/closelabel.gif" border=0/></a></span><b>&nbsp;</b></div>';
}

$(document).ready(function(){
	
	//Slideshow
    $('#slideshow').cycle({
        fx:     'scrollRight',
        speed:  '500',
        timeout: 8000,
        pager:  '#slider_nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#slider_nav li:eq(' + (idx) + ') a';
        }
    });
	
	// Banners
	jQuery("#banner_sup").cycle({
        fx: 'fade', 
        speed: 5000,
        speedIn: 500,
        speedOut: 500
    });
	
	jQuery("#banner_inf").cycle({
        fx: 'fade', 
        speed: 4000,
        speedIn: 500,
        speedOut: 500
    });
	$('#foto_news').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	//Bookmark
	$("a.jQueryBookmark").click(function(e){
        e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
        var bookmarkUrl = this.href;
        var bookmarkTitle = this.title;
 
        if (window.sidebar) { // For Mozilla Firefox Bookmark
                window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
        } else if( window.external || document.all) { // For IE Favorite
                window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
        } else if(window.opera) { // For Opera Browsers
                $("a.jQueryBookmark").attr("href",bookmarkUrl);
                $("a.jQueryBookmark").attr("title",bookmarkTitle);
                $("a.jQueryBookmark").attr("rel","sidebar");
        } else { // for other browsers which does not support
                 alert('Your browser does not support this bookmark action');
                 return false;
        }
	});
	
	// ToolTips
	$('#tel-tips').tipsy({delayOut: 1000, fade: true, gravity: 'ne'});
    $('.icon-wrapper').tipsy({delayOut: 1000, fade: true, html:true, gravity: 'nw'});
	

	// Logos Grupo
	$(".icon-wrapper").mouseover(function(event){
     	$(this).animate({
    		opacity: 1.0
  			}, 500, function() {
    			// Animation complete.
  		});
   	});	
	
	$(".icon-wrapper").mouseout(function(event){
     	$(this).animate({
    		opacity: 0
  			}, 500, function() {
    			// Animation complete.
  		});
   	});
	
	$(".icon-wrapper").click( function() {	
			aux=$(this).children().attr("href");
			window.open(aux);
			return false;
		});

	
	$(".icon-wrapper").animate({
    	opacity: 0
  		}, 50, function() {
    	// Animation complete.
  	});
	
	// LightsBoxs
	
	
	$('[rel="fancyiframe"]').fancybox({
	  'showCloseButton'		: false,
	  'titlePosition' 		: 'inside',
	  'titleFormat'			: formatTitle,
	  'width'				: 425,
	  'height'				: 350,
	  'type'				: 'iframe'
  	});
	
	$('[rel="fancyforms"]').fancybox({
	  'showCloseButton'		: false,
	  'titlePosition' 		: 'inside',
	  'titleFormat'			: formatTitle,
	  'scrolling'			: 'no',
	  'width'				: 600,
	  'height'				: 360,
	  'onClosed'			: function() {
	    $("#form_error").hide();
	}
  	});
	
	
	$('[rel="fancynews"]').fancybox({
		'showCloseButton'		: false,
		'titlePosition' 		: 'inside',
		'titleFormat'			: formatTitle,
		'hideOnContentClick'	: false
	});
	
	// vTicker
	$('#news-container').vTicker({
   		speed: 500,
		pause: 3000,
		animation: 'fade',
		mousePause: false,
		height: 142,
		showItems: 3
	});
	
	$("#contact_form").bind("submit", function() {

	if ($("#nombre").val().length < 3 || $("#apellidos").val().length < 3 || $("#telefono").val().length < 3 || $("#email").val().length < 7 || $("#comentarios").val().length < 3) {
	    $("#form_error").show();
	    $.fancybox.resize();
	    return false;
	}

	$.fancybox.showActivity();

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: "contacto.php",
		data		: $(this).serializeArray(),
		success: function(data) {
			$.fancybox(data);
		}
	});

	return false;
});
	  
});

