$(function(){
	$("#navMenu>li").hoverIntent(
		function(){
			$(this).addClass("selected");
			$(this).find("ul").slideDown("fast");
		},function(){
			$(this).removeClass("selected");
			$(this).find("ul").fadeOut("fast");
		}
	);
});
function link_expand() {
	$("a[rel*=expand]").each(function() {
		var destinazioneLink = $(this).attr("href");
		var target_var = $(this).attr("target");
		var cliccato=0;
		$(this).unbind("click").click(function() {
			cliccato=1;
		})
		.parents(":eq(0)")
		.unbind("click")
		.click( function() {
			if(cliccato==0){
				if(target_var=="_blank") window.open(destinazioneLink,'sponsor');
				else window.location = destinazioneLink;
			}
			cliccato=0;
		})
		.hover(function () {
			$(this).css({ cursor: "pointer" });
		}, function () {
			$(this).css({ cursor: "default" });
		});
	});
	$("a[rel*=expand_2]").each(function() {
		var destinazioneLink = $(this).attr("href");
		var target_var = $(this).attr("target");
		var cliccato=0;
		$(this).unbind("click").click(function() {
			cliccato=1;
		})
		.parents(":eq(1)")
		.unbind("click")
		.click( function() {
			if(cliccato==0){
				if(target_var=="_blank") window.open(destinazioneLink,'sponsor');
				else window.location = destinazioneLink;
			}
			cliccato=0;
		})
		.hover(function () {
			$(this).css({ cursor: "pointer" });
		}, function () {
			$(this).css({ cursor: "default" });
		});
	});
}
$(document).ready(function() {

	if ($("#EventiCorso1 .truncate_tit_evento").html()) $("#EventiCorso1 .truncate_tit_evento").truncate( 49,{ chars: /\s/, trail: [ "...", "..." ] });
	//$(document).pngFix();
	link_expand();
	$("#article-media").hover(function () {
		$("#article-media-tools").slideDown(100);
	},function () {
		$("#article-media-tools").slideUp(100);
	});
	if($('#sottosezione_carousel').html()!=null) $('#mycarousel').jcarousel();
	if($('#articolo_carousel').html()!=null) $('#mycarousel').jcarousel();
	if($('#news_carousel').html()!=null) $('#news_mycarousel').jcarousel();
	if($('#scheda_prodotto_carousel').html()!=null) $('#scheda_prodotto_mycarousel').jcarousel();
	$('ul#striscia_speciali li:last-child').css("margin-right","0px");
	$('#home_articoli ul li:last-child').css("margin-bottom","0px");
	$('ul#BoxMarketing li:last').css("margin-right","0px");
	$('ul#BoxAdv2 li:last').css("border-bottom","none");
	$('ul#BoxAdv1 li:last').css("border-bottom","none");
	$('ul#IfocusHome li:last-child').css("margin-right","0px");
	$('.altri ul li:last-child').css("border-bottom","none");
	$('#foot-content a:first-child').css("padding-left","0px");
	$('#article_navigation ul li:last-child').css("margin-bottom","0px");
	$('ul#archivio li:last-child').css("border-bottom","none");
	$('ul#altreFotoGallery li:last-child').css("margin-right","0px");

	// SLIDE HOMEPAGE
	function avvio_slide(){
		$('#slideshow').cycle({
			fx:      'scrollHorz',
			//timeout:  0,
			speed:  700,
			prev:    '#prev',
			next:    '#next',
			pager:   '#nav',
			pagerAnchorBuilder: pagerFactory
		});

    function pagerFactory(idx, slide) {
        var s = idx > 2 ? ' style="display:block"' : '';
        return '<li'+s+'><a href="#">0'+(idx+1)+'</a></li>';
    };
}
//function slide(){
	//SLIDE CYCLE HP
if ($("#slideshow").length>=1) {
	//$.get('/templates_images/x/wenchuan.xml?'+Math.random(), function(xml){
	$.get('/focus.php?'+Math.random(), function(xml){
		var html = '';
		var i = 0;
		$('articolo', xml).each(function(){
			i++;
			html += '<div class="text_cycleHp">';
			html += '<div class="tit_cycleHp">'+ $('occhiello', $(this)).text() +'</div>';
			html += '<div class="pic_cycleHp"><a href="'+ $('url', $(this)).text() +'" target="_blank" onmouseover="javascript:mouseOver();" onmouseout="javascript:mouseOut();"><img src="'+ $('path_img', $(this)).text() +'" /></a></div>';
			html += '<a href="'+ $('url', $(this)).text() +'" target="_blank"><div class="title">'+ $('titolo', $(this)).text() +'</div></a>';
			html += '<div class="summary">' + $('sommario', $(this)).text() +'</div>';
			//html += '<span class="provenienza">'+ '<span class="normal">' + 'to' + '</span>' + $('magazine', $(this)).text() +'</span>';
			html += '<span class="provenienza"><a href="'+ $('url', $(this)).text() +'" target="_blank">' + $('magazine', $(this)).text() +'</a></span>';
			html += '</div>';
		});
		fn_total = i;
		$('#slideshow').append(html);
		avvio_slide();
	});
}
//}


	$('a.new-window').click(function(){
		window.open(this.href);
		return false;
	});

	$("#top-search-input").focus(function() {
		if ( $(this).val().toUpperCase() == "RICERCA") {
			$(this).val('');
		}
	});

	$("#top-search-input").blur(function() {
		if ( $(this).val() == "") {
			$(this).val('RICERCA');
		}
	});

	$("body#archivio #search #top-search-input").focus(function() {
		if ( $(this).val().toUpperCase() == "PER PAROLA CHIAVE") {
			$(this).val('');
		}
	});

	$("body#archivio #search #top-search-input").blur(function() {
		if ( $(this).val() == "") {
			$(this).val('PER PAROLA CHIAVE');
		}
	});

	var pos = 0;
	$('#main-menu ul li').each( function() {
		if (typeof($(this).attr("id")) != 'undefined' ) {
			var mmId = $(this).attr("id");
			var mmSm = "#menu-" + mmId.replace("mm-", "");
			var lMar = pos + Math.round($(this).width() / 2);
			$(mmSm).css("margin-left", lMar);
			pos = pos + $(this).width();
		}
	});

	var visibleMenu = '';
	function showMenu(obj){
		if (typeof($(this).attr("id")) != 'undefined') {
			var mmId = $(this).attr("id");
			var mmSm = "#menu-" + mmId.replace("mm-", "");
			var newMenu = '#' + mmId;
			visibleMenu == '' ? $('#top-menu').addClass("deco") : 1;
			visibleMenu == '' ? 1 : $(visibleMenu + ' a').removeClass("selected");
			$(newMenu + ' a').addClass("selected");
			visibleMenu == '' ? 1 : $(visibleMenu.replace("mm-", "menu-")).hide();
			visibleMenu == '' ? $(mmSm).slideDown(1) : $(mmSm).show();
			visibleMenu = newMenu;
		} else {
			if (visibleMenu != '') {
				$(visibleMenu + ' a').removeClass("selected");
				$('#top-menu').removeClass("deco");
				$(visibleMenu.replace("mm-", "menu-")).fadeOut(1);
			}
			$(this).addClass("selected");
			visibleMenu = '';
		}
	}
	function hideMenu (obj) {
		if (visibleMenu != '') {
			$(visibleMenu + ' a').removeClass("selected");
			$('#top-menu').removeClass("deco");
			$(visibleMenu.replace("mm-", "menu-")).fadeOut(1);
		}
		$(this).addClass("selected");
		visibleMenu = '';
	}
	function foo() {};
	var config = {
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 20, // number = milliseconds for onMouseOver polling interval
		over: showMenu, // function = onMouseOver callback (REQUIRED)
		timeout: 50, // number = milliseconds delay before onMouseOut
		out: foo // function = onMouseOut callback (REQUIRED)
	};
	$("#main-menu ul li").hoverIntent(config);
	var config2 = {
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 10, // number = milliseconds for onMouseOver polling interval
		over: foo, // function = onMouseOver callback (REQUIRED)
		timeout: 1500, // number = milliseconds delay before onMouseOut
		out: hideMenu // function = onMouseOut callback (REQUIRED)
	};
	$("#menu-bar").hoverIntent(config2);
	if(("div.banner-e-catalogo div.big-square *").length > 1) {
		$("div.banner-e-catalogo h4, div.banner-e-catalogo ul").attr("style", "margin-left: 39px");
		//alert("rilevato il banner");
	}

	 //$('#menuNavigazione').onfocus();

	//MENU NUOVO - HACK PER IE6
	$("#subNav li").each( function(){
		$(this).hover( function(){
			$(this).addClass("selected");
		},function(){
			$(this).removeClass("selected");
		});
	});

});
function resetText(text) {
	$("#" + text).attr("value","");
}
// FUNZIONI STOP-PLAY SILDESHOW HP
function mouseOver(){
	$('#slideshow').cycle('pause');
	return false;
}
function mouseOut(){
	$('#slideshow').cycle('resume');
	return false;
}

// 首页播放Flash视频
function getVideoPath(vvid) {
	$.ajax({
		url: '/service/get_videopath.php?vid='+vvid+'',
		type: 'GET',
		dataType: 'xml',
		timeout: 1000,
		error: function(){
			alert('网络繁忙，请稍后刷新重试!!!');
		},
		success: function(xml){
			result = $(xml).find('result').text();
			if ( result == 'suee' ) {
				filepath = $(xml).find('durl url').eq(0).text();
				var html = '<object id="player" name="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="245" height="197"><param name="allowscriptaccess" value="always"/><param name="allowfullscreen" value="true"/><param name="movie" value="/templates_images/f/player.swf?autostart=true" /><param name="quality" value="high" /><param name="flashvars" value="file='+filepath+'"/><embed id="player_emb" flashvars="file='+filepath+'" src="/templates_images/f/player.swf?autostart=true" allowfullscreen="true" quality="high" type="application/x-shockwave-flash" width="245" height="197"></embed></object>';
				$('#video_flash').html(html);
			} else {
				result = $(xml).find('message').text();
				alert(result);
			}
		}
	});

}

function openPlayer ( vvid ) {
	getVideoPath( vvid );
}


