﻿
/*
    On page load
*/
$(document).ready(function() {

    // Menu laterale sinistro
	$("#menu").find("span.menuitem").each(function() {
		$(this).bind("click", function() {
			var ul = $(this).parent().children("ul");
			if(ul.css("display") == "none") {
				ul.slideDown(200);
			} else {
				ul.slideUp(200);
			}
		});
	});
	// Menu sedi
	$("#menusedi").find("span.menuitem").each(function() {
		$(this).bind("click", function() {
			var ul = $(this).parent().children("ul");
			if(ul.css("display") == "none") {
				ul.slideDown(200);
			} else {
				ul.slideUp(200);
			}
		});
	});
//	$("#menu li").bind("mouseenter", function() {
//	    if($(this).find("ul").length > 0) return;
//	    //$(this).stop();
//	    $(this).animate({
//	        backgroundColor: "#DDDDDD"
//	    }, 150);
//	} );
//	$("#menu li").bind("mouseleave", function() {
//	    if($(this).find("ul").length > 0) return;
//	    //$(this).stop();
//	    $(this).animate({
//	        backgroundColor: "#FFFFFF"
//	    }, 150);
//	} );
//	
	// Menu servizi
	$("#menuserv").find("span.menuitem").each(function() {
		$(this).bind("click", function() {
			var ul = $(this).parent().children("ul");
			if(ul.css("display") == "none") {
				ul.slideDown(200);
			} else {
				ul.slideUp(200);
			}
		});
	});
//	$("#menuserv li").bind("mouseenter mouseleave", function() { $(this).toggleClass("hover"); } );
//	

    // menu auto aprente
    if(document.location.href.indexOf("/sale/") > 0) {
        $("#msale").click();
    } else if(document.location.href.indexOf("boezio") > 0) {
        $("#mboezio").click();
    } else if(document.location.href.indexOf("regolo") > 0) {
        $("#mregolo").click();
    } else if(document.location.href.indexOf("marconi") > 0) {
        $("#mmarconi").click();
    }

	if($("#sliderhome")) {
		// vetrina homepage
		$("#sliderhome").load("vetrina.html", function() {
			$("#sliderhome").easySlider( {
				auto: true,
				continuous: true,
				controlsShow: false,
				speed: 900,
				pause: 2000,
				numeric: false,
				hoverPause: true
			});
		});
	}

	var baseUri = $("base").attr("href");

	$("#home3d").flash(
        { 
          src: "cu3er.swf",
          width: 360,
          height: 240,
          wmode: "transparent",
          flashvars: { xml: "cu3er.xml" }
        },
        { version: 9 }
    );
    
    $("#vtgen").flash(
        { 
          src: "cu3er.swf",
          width: 640,
          height: 280,
          bgcolor: "white",
          wmode: "transparent",
          flashvars: { xml: "virtual-tour/cu3er.xml.aspx" }
        },
        { version: 9 }
    );
    
    $(".promoboxhome div").flash(
        { 
          src: "http://www.youtube.com/v/GeOeJBkoJYs&amp;hl=it_IT&amp;fs=1&amp;rel=0&amp;color1=0xe1600f&amp;color2=0xfebd01",
          width: 180,
          height: 160,
          wmode: "transparent"
        },
        { version: 9 }
    );

	var cumulus = baseUri + "tagcloud.swf?r="+Math.random();
	var cumdata = encodeURI(
'<tags>'+
	'<a href="'+baseUri+'sale/day-office.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Day office</a>'+
	'<a href="'+baseUri+'sale/sale-riunioni.aspx?tc=1" style="font-size: 25px" color="0xFF7F00">Sale riunioni</a>'+
	'<a href="'+baseUri+'uffici/affitto-uffici.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Uffici</a>'+
	'<a href="'+baseUri+'sale/videoconferenza.aspx?tc=1" style="font-size: 12px" color="0xFF7F00">Videoconferenza</a>'+
	'<a href="'+baseUri+'uffici/coworking.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Coworking</a>'+
	'<a href="'+baseUri+'virtual-office/uffici-virtuali.aspx?tc=1" style="font-size: 18px" color="0xFF7F00">Virtual office</a>'+
	'<a href="'+baseUri+'uffici/office-sharing.aspx?tc=1" style="font-size: 30px" color="0xFF7F00">Office sharing</a>'+
'</tags>'
);
	var cumdataen = encodeURI(
'<tags>'+
	'<a href="'+baseUri+'en/sale/day-office.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Day office</a>'+
	'<a href="'+baseUri+'en/sale/sale-riunioni.aspx?tc=1" style="font-size: 25px" color="0xFF7F00">Meeting rooms</a>'+
	'<a href="'+baseUri+'en/uffici/affitto-uffici.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Offices</a>'+
	'<a href="'+baseUri+'en/sale/videoconferenza.aspx?tc=1" style="font-size: 12px" color="0xFF7F00">Videoconference</a>'+
	'<a href="'+baseUri+'en/uffici/coworking.aspx?tc=1" style="font-size: 15px" color="0xFF7F00">Coworking</a>'+
	'<a href="'+baseUri+'en/virtual-office/uffici-virtuali.aspx?tc=1" style="font-size: 18px" color="0xFF7F00">Virtual office</a>'+
	'<a href="'+baseUri+'uffici/office-sharing.aspx?tc=1" style="font-size: 30px" color="0xFF7F00">Office sharing</a>'+
'</tags>'
);

	$("#tagcloud").html('<object data="'+cumulus+'" width="201px" height="167px" type="application/x-shockwave-flash">'+
						'<param name="movie" value="'+cumulus+'"></param>'+
						'<param name="bgcolor" value="#FFFFFF"></param>'+
						'<param name="AllowScriptAccess" value="always"></param>'+
						'<param name="wmode" value="transparent"></param>'+
						'<param name="flashvars" value="tcolor=0x111111&tcolor2=0x336699&hicolor=0xFF9F22&tspeed=200&distr=true&mode=both&tagcloud='+cumdata+'">'+
						'</object>');

	$("#tagclouden").html('<object data="'+cumulus+'" width="201px" height="167px" type="application/x-shockwave-flash">'+
						  '<param name="movie" value="'+cumulus+'"></param>'+
						  '<param name="bgcolor" value="#FFFFFF"></param>'+
						  '<param name="AllowScriptAccess" value="always"></param>'+
						  '<param name="wmode" value="transparent"></param>'+
						  '<param name="flashvars" value="tcolor=0x111111&tcolor2=0x336699&hicolor=0xFF9F22&tspeed=200&distr=true&mode=both&tagcloud='+cumdataen+'">'+
						  '</object>');

});

Array.prototype.shuffle = function() {
	var i = this.length;
	if ( i == 0 ) return false;
	while ( --i ) {
		var j = Math.floor( Math.random() * ( i + 1 ) );
		var tempi = this[i];
		var tempj = this[j];
		this[i] = tempj;
		this[j] = tempi;
	}
};


function showVetrina(id) {
	window.open('vetrina.aspx?id='+id, '', 'width=399, height=450, toolbar=no, location=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
}

/*
    Center
*/

jQuery.fn.center = function(params) {

    var options = {
        vertical: true,
        horizontal: true
    }

    op = jQuery.extend(options, params);

    return this.each(function(){
        var $self = jQuery(this);
        var width = $self.width();
        var height = $self.height();
        var paddingTop = parseInt($self.css("padding-top"));
        var paddingBottom = parseInt($self.css("padding-bottom"));
        var borderTop = parseInt($self.css("border-top-width"));
        var borderBottom = parseInt($self.css("border-bottom-width"));
        var mediaBorder = (borderTop+borderBottom)/2;
        var mediaPadding = (paddingTop+paddingBottom)/2;
        var halfWidth = (width/2)*(-1);
        var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder;
        var cssProp = {
            position: 'absolute'
        };
        if(op.vertical) {
            var ty = ($(window).height() - height) / 2 + $(document).scrollTop();
            var diff = Math.abs(ty - parseInt($self.css("top")));
            if(diff > 2) {
                if(ty - parseInt($self.css("top")) > 0) {
                    cssProp.top = parseInt($self.css("top")) + diff / 6;
                } else if(ty - parseInt($self.css("top")) < 0) {
                    cssProp.top = parseInt($self.css("top")) - diff / 6;
                } else {
                    cssProp.top = parseInt($self.css("top"));
                }
            }
        }
        if(op.horizontal) {
            cssProp.left = ($(document).width() - width) / 2;
        }
        $self.css(cssProp);
    });
};


