/**
 * $.include - script inclusion jQuery plugin
 * Based on idea from http://www.gnucitizen.org/projects/jquery-include/
 * @author Tobiasz Cudnik
 * @link http://meta20.net/.include_script_inclusion_jQuery_plugin
 * @license MIT
 */
// overload jquery's onDomReady
if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
	document.removeEventListener( "DOMContentLoaded", jQuery.ready, false );
	document.addEventListener( "DOMContentLoaded", function(){ jQuery.ready(); }, false );
}
jQuery.event.remove( window, "load", jQuery.ready );
jQuery.event.add( window, "load", function(){ jQuery.ready(); } );
jQuery.extend({
	includeStates: {},
	include: function(url, callback, dependency){
		if ( typeof callback != 'function' && ! dependency ) {
			dependency = callback;
			callback = null;
		}
		url = url.replace('\n', '');
		jQuery.includeStates[url] = false;
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.onload = function () {
			jQuery.includeStates[url] = true;
			if ( callback )
				callback.call(script);
		};
		script.onreadystatechange = function () {
			if ( this.readyState != "complete" && this.readyState != "loaded" ) return;
			jQuery.includeStates[url] = true;
			if ( callback )
				callback.call(script);
		};
		script.src = url;
		if ( dependency ) {
			if ( dependency.constructor != Array )
				dependency = [dependency];
			setTimeout(function(){
				var valid = true;
				$.each(dependency, function(k, v){
					if (! v() ) {
						valid = false;
						return false;
					}
				})
				if ( valid )
					document.getElementsByTagName('head')[0].appendChild(script);
				else
					setTimeout(arguments.callee, 10);
			}, 10);
		}
		else
			document.getElementsByTagName('head')[0].appendChild(script);
		return function(){
			return jQuery.includeStates[url];
		}
	},
	readyOld: jQuery.ready,
	ready: function () {
		if (jQuery.isReady) return;
		imReady = true;
		$.each(jQuery.includeStates, function(url, state) {
			if (! state)
				return imReady = false;
		});
		if (imReady) {
			jQuery.readyOld.apply(jQuery, arguments);
		} else {
			setTimeout(arguments.callee, 10);
		}
	}
});

$.include(baseUrl +'/js/cufon-yui.js');
$.include(baseUrl +'/js/Arial_Rounded_MT_Bold_400.font.js');
$.include(baseUrl +'/js/jquery.easing.1.3.js');
$.include(baseUrl +'/js/mwheelIntent.js');
$.include(baseUrl +'/js/jquery.mousewheel.js');
$.include(baseUrl +'/js/jquery.jscrollpane.min.js');
$.include(baseUrl +'/js/jquery.vticker.1.4.js');
$.include(baseUrl +'/js/jquery.cycle.all.min.js');
$.include(baseUrl +'/js/jquery.prettyPhoto.js');
$.include(baseUrl +'/js/jquery.qtip.min.js');
$.include(baseUrl +'/js/cufon-yui.js');
$.include(baseUrl +'/js/Folks_400-Folks_700.font.js');
$.include(baseUrl +'/js/jQuery.rollChildren.js');
$.include(baseUrl +'/js/jquery.zweatherfeed.js');

$.animacionBuho = {
	direccion : true,
	timer: null,
	pausar: false,
	animar : function () {
		clearTimeout($.animacionBuho.timer);
		$("#menu").animate({
					marginTop: ($.animacionBuho.direccion ? 285 : 300) + "px"
				}, {
					duration: 1000, 
					complete: function () {
						$.animacionBuho.direccion = !$.animacionBuho.direccion;
						$.animacionBuho.timer = setTimeout($.animacionBuho.animar, 0);
					}
				}
		);
	}	
};

$.imagenNoticia = {
	imagenLocal: false,
	actualizarImagen: function (strImagen) {
		$.imagenNoticia.imagenLocal = true;
		$("#imagenNoticia").attr("src",baseUrl + "/upload_user/" +strImagen);
		$("#TraduccionNoticia_imagen").val("upload_user/" +strImagen);
	}
};

$(document).ready(function () {
	
	//Cufon.replace('.texto_uno',{ 
	//});
	
	$("<div id='clima'></div>").appendTo($("#contendedor_interno"));
	$('#clima').weatherfeed(['COXX0008']).css({display: "none"});

	
	$.animacionBuho.animar();
	
	$("#menu").hover(function () {
		$(this).stop();
	}, function () {
		$.animacionBuho.animar();
	});
	
	$(".scroll-pane").jScrollPane({verticalDragMaxHeight:40, verticalDragMinHeight:40, autoReinitialise: true});
	
	
	$('.tickerNews > ul').rollchildren({  
        delay_time : 3000,  
        loop : true,  
        pause_on_mouseover : true,  
        roll_up_old_item : true,  
        speed: 'slow'   
	});  
	//$('.tickerNews > ul').innerfade({ animationtype: 'slide', speed: 750, timeout: 2000, type: 'random', containerheight: '150px' });
	
	/*
	$('.tickerNews').vTicker({
		speed: 500,
		pause: 3000,
		animation: 'fade',
		direction: 'up',
		mousePause: true,
		showItems: 1,
		height: 150
	});
	 */
	/*
	$(function(){
		$('.tickerNews').vTicker({ 
			speed: 500,
			pause: 3000,
			animation: 'fade',
			direction: 'up',
			mousePause: true,
			showItems: 1,
			height: 150
		});
	});*/
	
	$("#TraduccionNoticia_imagen").change(function () {
		$("#imagenNoticia").attr("src",baseUrl +"/" + $("#TraduccionNoticia_imagen").val());
	});
	
	$("#imagenNoticia").attr("src", baseUrl +"/" +$("#TraduccionNoticia_imagen").val());
	
	$("#slide").cycle({
		prev:    '#flecha_izquierda',
		next:    '#flecha_derecha',
		cleartypeNoBg: true
	});
	
	// auto URLs
	$("#TraduccionNoticia_titulo").change(function () {
		if($("#TraduccionNoticia_url").val().toLowerCase() == "") {
			var url = $(this).val().toLowerCase();
			url = url.replace(/\s+/gi, "-");
			url = url.replace(/[\.,]+/gi, "");
			$("#TraduccionNoticia_url").val(url);
		}
	});
	$("#TraduccionSeccion_titulo").change(function () {
		if($("#TraduccionSeccion_url").val().toLowerCase() == "") {
			var url = $(this).val().toLowerCase();
			url = url.replace(/\s+/gi, "-");
			url = url.replace(/[\.,]+/gi, "");
			$("#TraduccionSeccion_url").val(url);
		}
	});
	
	$("a[rel^='prettyPhoto']").prettyPhoto();
	$('a[title]').qtip({
		position: {
			my: "center left",
			at: 'center right'
	   }});
	//Cufon.replace('.cont_item_txt',{ 
	//});
});
