var videoFunctions = [];

var hoverInChildHrefOverFunc = function(){
	var imgSelect = $(this).find('img');
    imgSelect.attr('src',imgSelect.attr('src').replace("_OFF","_ON"));
}
var hoverInChildHrefOutFunc = function(){
	var imgSelect = $(this).find('img');
    imgSelect.attr('src',imgSelect.attr('src').replace("_ON","_OFF"));
}

$(function(){
	var common_data = $("#script-data").metadata({type: 'elem', name: 'script'});

	$('.hide').hide();

    $(".hoverInParentTD").mouseover(function(){
        var imgSelect = $(this).parent().prev().find('img');
        imgSelect.attr('src',imgSelect.attr('src').replace("_OFF","_ON"));
    }).mouseout(function(){
        var imgSelect = $(this).parent().prev().find('img');
        imgSelect.attr('src',imgSelect.attr('src').replace("_ON","_OFF"));
    });

    $(".hoverInChildHref").mouseover(hoverInChildHrefOverFunc).mouseout(hoverInChildHrefOutFunc);

    $('a.closeCalendar').click(function(){
        if($('#contCalendario').is(':visible')){
            $(this).find('img').attr('src', common_data.img_prefix + 'aprCalendario_OFF.gif');
            $(this).attr('title','apri calendario');
        }else{
            $(this).find('img').attr('src', common_data.img_prefix + 'chiuCalendario_OFF.gif');
            $(this).attr('title','chiudi calendario');
        }
        $('#contCalendario').slideToggle();
        return false;
    });

    $('a.open').click(function(){
        if($(this).parent('div').next('div').is(':visible')){
            $(this).html(common_data.open+' +');
            $(this).attr('title',common_data.open);
        }else{
            $(this).html(common_data.close+' -');
            $(this).attr('title', common_data.close);
        }
        $(this).parent('div').next('div').slideToggle();
        return false;
    });

    //contenuto flash
    $('div.flashContent').each(function(){
        var data = $(this).metadata();

        flashembed(this, {
                src: data.url,
                width: data.w || '',
                height: data.h || '',
                wmode: "opaque",
                allowfullscreen: true,
                allowscriptaccess: "always"
            }
        );
    });
    $('#inputCerca,#inputCercaGrande').attr('value', $('#inputCerca').attr('title'));
    $('#inputCerca,#inputCercaGrande').focus(function(){
    	if($(this).attr('value')== $('#inputCerca').attr('title')){
    		$(this).attr('value','');
    	}
    });
    $('#inputCerca,#inputCercaGrande').blur(function(){
    	if($(this).attr('value')== ''){ 
    		$(this).attr('value', $('#inputCerca').attr('title'));
    	}
    });
    
    // video
	for (var i = 0; i < videoFunctions.length; i++) {
		videoFunctions[i]();
	}
});
