

//Create display div
function createDisplay() {
    var container = document.createElement('div');
    container.id = 'display';
    var jcontainer = jQuery(container);
    jcontainer.appendTo("body");
}

//Destroy display div
function destroyDisplay() {
    jQuery("#display")
        .fadeOut("slow", function () {
            jQuery("#display").remove();
        });
}

//Render display div
function renderDisplay(content) {
    var element = document.getElementById("display");
    if(String(element)!="undefined") {
        var $display = jQuery("#display");
        $display.append(content);
        var left = jQuery(document).width()/2-$display.outerWidth()/2;
        var top = jQuery(document).height()/2-$display.outerHeight()/2;
        $display
            .css({top:top,left:left})
            .fadeIn("slow");
    }
}

jQuery(window).load(function(){

    var host = "http://www.corachan.com";

    createDisplay();

	if(jQuery(".link-map").length>0) {
		jQuery(".link-map").click( function() {
            var link = '/maps/index.asp?l=' + current_lang;
            if(jQuery("#text p span.block").length>0) link += "&block=" + jQuery("#text p span.block").text();
			jQuery("#lightbox-content").html('<iframe id="googlemaps" height="550" frameborder="0" width="570" scrolling="no" src="'+ host + link + '" marginwidth="0" marginheight="0"/>');
			jQuery(".div_lightbox").show();
			jQuery(".div_lightbox").lightBox().click();			
		});
	}
    
    jQuery("#videolink").click(function () {
		initVideoLightBox("25196717");
		jQuery(".div_lightbox").show();
		jQuery(".div_lightbox").lightBox().click();
        return false;
    });
    
    jQuery("#inner-videolink").click(function () {
        if(jQuery("#lightbox-container").length==0) jQuery("body").append('<div id="lightbox-container"><div id="lightbox-content" class="div_lightbox" style="display: none;"></div></div>');
        jQuery("#lightbox-content").html('<iframe src="http://player.vimeo.com/video/26864024?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="700" height="525" frameborder="0"></iframe>');
										
		jQuery(".div_lightbox").show();
		jQuery(".div_lightbox").lightBox().click();
        return false;
    });    

	jQuery(".corachan-views-PersonList #search_form").submit( function() {
		jQuery(this).find(".loading").show();
	});

    jQuery("[name='googleSearchFrame']").attr("id", "googleResultsSearch");

    if(jQuery(".slider").length>0) {
        jQuery(".slider_loading").hide();
        jQuery(".slider_container").show();

        jQuery(".slider").each(function (index, element) {
            jQuery(element).attr("id","slider_" + index);

            var slider = jQuery(element).sudoSlider({
                auto: true,
                numeric: true,
				speed: 1000,
				pause: 6000,
				continuous: true
                //controlsFade: false,
                //prevHtml: '<div class="next_container"><a href="#" class="prevBtn"><img src="/site/images/left.png" /></a></div>',
                //nextHtml: '<div class="prev_container"><a href="#" class="prevBtn"><img src="/site/images/right.png" /></a></div>'
            });
            element.slider = slider;
        });
        
        jQuery(".prevBtn, .nextBtn, .slider").hover(
            function () {
                // Mousein
                jQuery(".prevBtn, .nextBtn").show();
            }, 
            function () {
                //Mouse out
                jQuery(".prevBtn, .nextBtn").hide();
            }
        );
        jQuery(".prevBtn, .nextBtn").hide();

        jQuery("ol.controls li:last").css({marginRight:0});
        
        /*
        jQuery(".prevBtn, .nextBtn").css({opacity: "0.3"});
        
        jQuery(".prevBtn, .nextBtn").mouseover(function () {
            jQuery(this)
            .animate({opacity: 1}, 300);
        })
        .mouseout(function () {
            jQuery(this)
            .animate({opacity: 0.1}, 300);
        });
        */

        createFancyEvents();
    }

    function initVideoLightBox(id) {
        if(jQuery("#lightbox-container").length==0) jQuery("body").append('<div id="lightbox-container"><div id="lightbox-content" class="div_lightbox" style="display: none;"></div></div>');
        jQuery("#lightbox-content").html('<iframe src="http://player.vimeo.com/video/' + id + '?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="891" height="490" frameborder="0"></iframe>');
    }
    
    function renderVideoLightBox(element) {
        var rel = element.attr("rel");
        if(element.hasClass("video")) initVideoLightBox(rel);
        jQuery(".div_lightbox").show();
        jQuery(".div_lightbox").lightBox().click();
    }

    function createFancyEvents() {
        if(String(current_lang)=="undefined") current_lang = 'es';
        if(jQuery(".slider .video").length>0) {
            jQuery(".slider .video").click(function () {
                renderVideoLightBox(jQuery(this));
                return false;
            });
        }
    }

    jQuery("#relacionats .video").click(function () {
        renderVideoLightBox(jQuery(this));
    });    

});

