/**
 * Dpee - gestione sito
 * Copyright (c) 2011 S.2T
 * Licensed under: http://creativecommons.org/licenses/by-nc-nd/2.5/it/
 * Date: 15/08/2010
 * @author S.2T
 * @version 0.1.2
 */
 
 	var ContentHeightDelta=160;
	  
	function GetDocName(fullString, subString) { 
		if (fullString.lastIndexOf(subString) == -1) { 
			return ""; 
		} 
		else { 
			return fullString.substring(fullString.lastIndexOf(subString)+1, fullString.length); 
		} 
	}

	function GetFullPath(fullString, subString) { 
		if (fullString.lastIndexOf(subString) == -1) { 
			return ""; 
		}
		else { 
			return fullString.substring(0, fullString.lastIndexOf(subString)); 
		} 
	}
		
	function SetHeight(dt){
		NewHeight=$(window).height()-dt;
		$("#content").css({'min-height':NewHeight});
	}
	
	
	$(document).ready(function(){
		PathName 	= window.location.pathname;
		DocName 	= GetDocName(PathName,'/');
		DocName 	= DocName.toLowerCase();
		opc			= 0.7;
		CreatedMap	= false;
		Indirizzo	= "Corso San Maurizio, 81 10124 Torino";
		TestoInd	= "<b>DPEE S.r.l. </b><br/>Corso San Maurizio, 81 - Torino";
		SetHeight(ContentHeightDelta);
				
		
		$("a[rel=external]").click(function(){
      		window.open(this.href);
       		return false;
		});
		
		$("a[rel='contatti']").colorbox({width:"600px", inline:true, opacity:opc, href:"#contatti", 
										onLoad:function(){
											$("[rel='inner_box']").hide();
											$(".content_cubo").show("fast");
										}
								});

		$("a[rel='dove_siamo']").colorbox({width:"800px", inline:true, opacity:opc, href:"#dove_siamo",
										onLoad:function(){
											$("[rel='inner_box']").hide();
											$(".content_cubo").show("fast");
											
										},
										onComplete:function(){
											if (!CreatedMap){
										 		$("#mappa").gMap({ markers: [{ address : Indirizzo, html: TestoInd, popup: true }],zoom: 15 });
										 	 	CreatedMap=true;
										 	}
										}
								});
		
		$("[rel='members']").click(function(){
			lgn="mlogin.html";
			if (DocName=="english.html") {
				lgn="en_mlogin.html";
			}
			$("#members").load(lgn, function(){
				$.colorbox({width:"800px", inline:true, opacity:opc, href:"#members", 
							onComplete:function(){
								$("[rel='inner_box']").hide(); 
								$(".content_cubo").show("fast");
								$(".invia_cl").click(function(){
									query="login.php?user=" + $("#user").val() + "&password=" + $("#password").val();
									$.getJSON(query, function(data) {
										if (data.isok){
											//$.colorbox.close();
											var isok=true;
											query="getSoftware.php?user=" + $("#user").val() + "&password=" + $("#password").val() + "&id=" + data.id;
											$("#members").load(query, function(){
												$.colorbox({width:"800px", inline:true, opacity:opc, href:"#members"});
											});
										}
									});
								});
							}
				});
			});
		});

		$("#contatori").click(function(){
			$("[rel='inner_box']").hide();
			$(".content_prodotti_contatori").show("fast");
		});
		
		$("#campione").click(function(){
			$("[rel='inner_box']").hide();
			$(".content_prodotti_campione").show("fast");
		});
		
		$("#quadro").click(function(){
			$("[rel='inner_box']").hide();
			$(".content_prodotti_quadro").show("fast");
		});
		
		$("#software").click(function(){
			$("[rel='inner_box']").hide();

			$(".content_prodotti_software").show("fast");
		});
		
		$("a[rel='contatore01']").colorbox({width:"800px", inline:true, opacity:opc, href:"#contatore01"});
		$("a[rel='contatore02']").colorbox({width:"800px", inline:true, opacity:opc, href:"#contatore02"});
		$("a[rel='contatore03']").colorbox({width:"800px", inline:true, opacity:opc, href:"#contatore03"});
		$("a[rel='quadro01']").colorbox({width:"800px", inline:true, opacity:opc, href:"#quadro01"});
		$("a[rel='campione01']").colorbox({width:"800px", inline:true, opacity:opc, href:"#campione01"});
		$("a[rel='campione02']").colorbox({width:"800px", inline:true, opacity:opc, href:"#campione02"});
		$("a[rel='campione03']").colorbox({width:"800px", inline:true, opacity:opc, href:"#campione03"});
		$("a[rel='software01']").colorbox({width:"800px", inline:true, opacity:opc, href:"#software01"});
		$("a[rel='software02']").colorbox({width:"800px", inline:true, opacity:opc, href:"#software02"});
		$("a[rel='software03']").colorbox({width:"800px", inline:true, opacity:opc, href:"#software03"});
		$("a[rel='software04']").colorbox({width:"800px", inline:true, opacity:opc, href:"#software04"});
		$("a[rel='software05']").colorbox({width:"800px", inline:true, opacity:opc, href:"#software05"});

	});
