$(document).ready(function() {
	
		//Location
	$("#map").attr("style", "width:655px; height:860px"); //665px

	$(".mainballoon .row:eq(0)").removeClass("row").addClass("frow");

	var lastp=0;
	$(".submenu li").click(function(){
		$(".submenu li").removeClass("sel");
		$(this).addClass("sel");
		if ($(".tablecontent").length != 0)
		{
			$(".tablecontent").hide();
			$("#tableconten"+this.id).fadeIn();
		}
		else
		{
			$(".content").hide();
			$("#conten"+this.id).fadeIn();
		}
		lastp=parseInt(this.id.substr(1));
	});
	
	//Sponsors
	if ($(".sponsors .submenu li").length != 0)
	{
		rotatep();
		function rotatep() { 
			lastp++;
			if (lastp > $(".submenu li").size()) lastp=1;
			$('.submenu li:eq('+(lastp-1)+')').click();
		  	window.setTimeout(rotatep, 10000); 
		}
	}
	
	//FAQ
	$(".faq").expandAll();
	$(".faq  h5.expand").toggler();
	
	//Home
	$(function() {
	    $(".trackmenu").jCarouselLite({btnNext: ".rarrow-big", btnPrev: ".larrow-big", mouseWheel: true, circular: true, 
	    visible: 9, scroll: 1, speed: 300, easing: "easeOutBack", 
	    beforeStart: function(a) {
	    	var cur=Math.floor(a.length /2);
	    	$("#"+a[cur].id+"-session").animate({opacity: "hide", top: "70"}, "fast");
	    },
	    afterEnd: function(a) {
				var cur=Math.floor(a.length /2);
	        	$(".trackmenu li").removeClass("sel");
                $(a[cur]).addClass("sel");
				$("#"+a[cur].id+"-session").stop(true, true).animate({opacity: "show", top: "75"}, "slow");
			}
	    });
	});
	$("#etl-session").stop(true, true).animate({opacity: "show", top: "75"}, "slow");
    
    //Agenda
    $(".agenda .butt").click(function(){
		$(".agenda .butt").removeClass("sel");
		$(this).addClass("sel");
		if (this.id=='notopic')
		{
			$(".agenda .s").fadeTo(0, 1);
			//$(".tpc img").fadeTo(0, 1);
		}
		else
		{ 
			$(".agenda .s").fadeTo(0, 0.5);
			$(".agenda .t"+this.id).fadeTo(0, 1);
			//$(".tpc img").fadeTo(0, 0.5);
			//$(".tpc ."+this.id+"-r").fadeTo(0, 1);
		}
	});
    
	//Sessions
	$(".sessions .butt").click(function(){
		$(".sessions .butt").removeClass("sel");
		$(this).addClass("sel");
		$(".info").hide();
		$("#"+this.id+"-info").fadeIn();
	});
	$(".sessions .sessionbox a").click(getPageDestination); 
    $(".sessions .fballoon a").click(getPageDestination);
	$("#sqldev-info").show();
	if ($(".sessions").length != 0) getPageDestination();
	
	//Speakers
	$(".speakers .frame img").each(function(){
			$(this)
				.after($('<div />')
					.attr('class', 'tooltip')
					.html('<div class="ltooltip">'+$(this).attr('title')+'</div><div class="rtooltip"></div>'))
				.attr('title', '');
		})
		.hover(function(){
			var t = $(this).next('.tooltip');
			t.fadeIn()
				.css('top', $(this).position().top+t.height()/2)
				.css('left',$(this).position().left-t.width()-10);
		}, function(){
			$(this).next('.tooltip').fadeOut();
	});

});

//Location
var map;
var shapes = new Array();
function initMap()
{
	map = new VEMap('map');
	map.SetDashboardSize(VEDashboardSize.Small);
	map.LoadMap(new VELatLong(45.484537308483304, 9.194698333740236), 15);
	
	
	
	shapes[1] = addShape(45.4842, 9.187574386596674, "subway.png", "Stazione Metro Porta Garibaldi", "Milano");
	shapes[2] = addShape(45.485272704419445, 9.187094735145564, "station.png", "Stazione FS Porta Garibaldi", "Milano");
	shapes[3] = addShape(45.48699985725784, 9.205435216426858, "station.png", "Stazione FS Milano Centrale", "Milano");
	shapes[4] = addShape(45.46175040442564, 9.275764748454078, "airport.png", "Aeroporto Milano Linate", "Milano<br /><br /><img src='images/taxi.png' alt='' /><br /><strong>In taxi fino all'albergo</strong><br />Tempo: 25 min. circa<br />Prezzo indicativo: 30 &euro;");
	shapes[5] = addShape(45.633308552226275, 8.733300045132632, "airport.png", "Aeroporto Milano Malpensa", "Milano<br /><br /><img src='images/taxi.png' alt='' /><br /><strong>In taxi fino all'albergo</strong><br />Tempo: 50 min. circa<br />Prezzo indicativo: 75 &euro;");
	
	shapes[6] = addShape(45.483085132421074, 9.185032000000007, "phyellow.png", "Executive Lounge", 'Via Alessio Di Tocqueville, 3 - 20154 Milano<br /><br /><a href="http://www.executivelounge.it">www.executivelounge.it</a>');
	shapes[7] = addShape(45.48273913241945, 9.187364999999993, "phblue.png", "Hollywood", 'Corso Como, 15 - 20154 Milano<br /><br /><a href="http://www.discotecahollywood.it">www.discotecahollywood.it</a>');
	shapes[8] = addShape(45.48273913241945, 9.187837068786605, "phred.png", "Corso Como", "Milano");
	
	shapes[9] = addShape(45.482, 9.1857, "phunahotel.png", "UNA Hotel Tocq****", 'Via A. De Tocqueville, 7/D - 20154 Milano<br /><br /><a href="http://www.unahotels.it/it/una_hotel_tocq/hotel_milano_corso_como.htm">Prenota</a>');
	shapes[10] = addShape(45.48865613244682, 9.183325767517081, "phholidayinn.png", "Holiday Inn Milan Garibaldi Station****", 'Via U. Bassi, 1/A - 20159 Milano<br /><br /><a href="http://www.himilangaribaldi.com">Prenota</a>');
	shapes[11] = addShape(45.481134174752476, 9.191136360168455, "phnhhotel.png", "NH Grand Hotel Verdi****", 'Via Melchiorre Gioia, 6 - 20124 Milano<br /><br /><a href="http://www.nh-hotels.it/nh/it/hotels/italia/milano/nh-grand-hotel-verdi.html">Prenota</a>');
	shapes[12] = addShape(45.48501563033949, 9.183759000000014, "phachotel.png", "Hotel AC Milano****", 'Via Tazzoli, 2 - 20154 Milano<br /><br /><a href="http://www.ac-hotels.com">Prenota</a>');
	
	shapes[0] = addShape(45.4837832223858, 9.185586869716537, "shape.png", "Microsoft SQL Server &amp; Business Intelligence Conference 2010<br /><br />ATAHotel executive ****", 'Viale Don Luigi Sturzo, 45 - 20154 Milano<br /><br /><a href="http://www.atahotels.it/struttura.asp?id=executive&data=gg/mm/aaaa&notti=1&adulti=1&child=0&section=&ln=ita&promo=offerte&promoS=executive">Prenota</a>');
}
function addShape(lat, long, icon, title, street)
{

	var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(lat, long));
	
	shape.SetCustomIcon('<img src="images/'+icon+'" alt="" />');
	shape.SetTitle(title);
	shape.SetDescription(street);
	map.AddShape(shape);
	
	return shape.GetID();
}
function route(index, toShape)
{
	var base = map.GetShapeByID(shapes[0]);
	var shape = map.GetShapeByID(shapes[index]);
	var start = (toShape ? shape.GetPoints()[0] : base.GetPoints()[0]);
	var end = (toShape ? base.GetPoints()[0] : shape.GetPoints()[0]);
	
	map.DeleteRoute();
	map.GetRoute(start, end, VEDistanceUnit.Kilometers, VERouteType.Quickest);
}
function centerMap(index)
{
	map.DeleteRoute();

	var shape = map.GetShapeByID(shapes[index]);
	//map.SetCenter(shape.GetPoints()[0]);
	map.SetMapView(shape.GetPoints());
}

//Sessions
function getPageDestination()
{
	window.setTimeout(function() {
		var url=document.location.href;
		var i=url.indexOf("#");
		if (i>-1)
		{
			var s=url.substr(i+1);
			if(s.indexOf("s")==0) 
				$("#t2").click();
			else if(s.indexOf("t")==0) 
			{
				$("#t1").click();
				$("#"+s.substr(1)).click();
			}
			else 
				return;
			scrollToEl(document.getElementById(s));
		}
	}, 1);
}

function scrollToEl(el)
{
	var x = 0;
	var y = 0;
	while(el != null){
		x += el.offsetLeft;
		y += el.offsetTop;
		el = el.offsetParent;
	}        		      
	window.scrollTo(x,y);
}

$(document).ready(function() {
			//Registration-step
			$(".registration-step input:radio").attr("autocomplete", "off");
			
			$(".registration-step input:radio").click(function(){
				$(".products .box").fadeTo(0, 0.6);
				$(".prodopt select").attr("disabled", "disabled");
				var eid=$(this).next().attr("id");
				$("#"+eid+" .box").fadeTo(0, 1.0);
				$("#"+eid+" select").removeAttr("disabled");
			});
			
			$(".registration-step input:radio:eq(2)").click();
		});
