var Site = {
	
	
	clearAllCont: function() {
	
		$(".theworld-cont").removeClass("theworld-cont-selected");
		//$(".theworld-cont").css("opacity", 0.6);	
	
	},


	debug: function() {
	
		// set dim opacity decimal
		var opacityOut = "0.99";
		
		// map background image
		$(".theworld-label").hover(
			function()
			{
				//$("#theworld-map-image").attr("src", "/wp-content/themes/tdd/images/map.continents.face.png");
			},		
			function()
			{
				//$("#theworld-map-image").attr("src", "/wp-content/themes/tdd/images/map.continents.blue2.png");
			}
		);
				
			
		
	
		
		// connect dim behaviour labels
		$(".theworld-label").css("opacity", opacityOut);		
		$(".theworld-label").hover(
			function()
			{
				$(this).css("opacity", "0.99");
			},		
			function()
			{
				if ($(this).hasClass("theworld-label-selected")) {
				} else {
					$(".theworld-label").css("opacity", opacityOut);
					$(this).css("opacity", "0.99");
				}
		});
		

		// preselect europe
		$("#theworld-label-europe").css("opacity", "0.99");			
		
	
				
		// connect label behaviour
		$("#theworld-label-northamerica").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-northamerica").fadeIn();						
			}
		);	
		$("#theworld-label-latinamerica").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-latinamerica").fadeIn();							
			}
		);	
		$("#theworld-label-europe").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-europe").fadeIn();							
			}
		);			
		$("#theworld-label-middleeast").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-middleeast").fadeIn();							
			}
		);			
		$("#theworld-label-africa").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-africa").fadeIn();							
			}
		);			
		$("#theworld-label-asia").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-asia").fadeIn();							
			}
		);			
		$("#theworld-label-oceania").click(
			function() {
				$(".theworld-label").css("opacity", opacityOut);
				$(this).css("opacity", "0.99");
				$(this).addClass("theworld-label-selected");				
				$(".theworld-countries").hide();
				$("#theworld-countries-oceania").fadeIn();							
			}
		);		
		
		
	}, 


	start: function() {
		
		// ie6
		
		if ($.browser.msie() && $.browser.version.number() == 6)
		{	
			alert("You browser is outdated. You should consider upgrading to a more secure browser.\nVisit http://www.microsoft.com or http://www.firefox.com");
		}
		
		
		// news
		if ($(".newsbox")) { $(".newsbox").cycle({ 
			fx:     'scrollRight', 
			speed:  300
		}); }
	
	
		Site.cites();
		Site.slide("#sidebar-menu ul", 25, 20, 150, .6);
		
		$(".sidebar-box").hover(
			function()
			{
				$(this).css("border", "1px solid #aaa");
			},		
			function()
			{
				$(this).css("border", "1px solid #ddd");
			});
		

		//vw sidebar link
		$(".page-item-51 a").attr("href", "/virtualworkshop").css("color", "#E26305").append('<span style="padding-left:10px;"><img src="/wp-content/themes/tdd/images/new.png" /></span>');

		
		// handle dialog events
		$('.theworld-countries-list-link').fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0,
			'frameWidth'			: 850,
			'frameHeight'			: 550,
			'hideOnContentClick': 	false
		});
		
		// vw
		/*
		$('#vw-popup').fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.2,
			'frameWidth'			: 1000,
			'frameHeight'			: 650,
			'hideOnContentClick': 	false
		});	
		*/
		
		
		// states?
		if ($("#theworld-countries-states-link"))
		{
			$("#theworld-countries-states-link").click(function(){
				$(".theworld-countries").hide();
				$("#theworld-countries-states").fadeIn();
				
			});
		}
		if ($("#theworld-countries-states-back-link"))
		{
			$("#theworld-countries-states-back-link").click(function(){
				$("#theworld-countries-states").hide();
				$("#theworld-countries-americas").fadeIn();
				
			});
		}		
		
		
		
		// the world maps	
		$(".theworld-cont").css("cursor", "pointer");
	
		$(".theworld-cont").mouseenter(		 
		  function () {
		   if (!$(this).hasClass("theworld-cont-selected")) {			  
			$(this).animate({ 
				opacity: 0.99,
				backgroundColor: "#fff"
			  }, 500 );
		   }
		  }
		);
		
		$(".theworld-cont").mouseleave(		 
		  function () {
		   if (!$(this).hasClass("theworld-cont-selected")) {			  
			$(this).animate({ 
				opacity: 0.6,
				backgroundColor: "transparent"
			  }, 200 );
		   }
		  }
		);
		
		$("#theworld-cont-americas").click(
			function() {
				Site.clearAllCont();
				$(this).addClass("theworld-cont-selected");
				$(".theworld-countries").hide();
				$("#theworld-countries-americas").fadeIn();						
			}
		);		
		$("#theworld-cont-europe").click(
			function() {	
				Site.clearAllCont();		
				$(this).addClass("theworld-cont-selected");		
				$(".theworld-countries").hide();
				$("#theworld-countries-europe").fadeIn();
			}
		);	
		$("#theworld-cont-meafrica").click(
			function() {
				Site.clearAllCont();				
				$(this).addClass("theworld-cont-selected");			
				$(".theworld-countries").hide();
				$("#theworld-countries-meafrica").fadeIn();
			}
		);	
		$("#theworld-cont-chinaasia").click(
			function() {
				Site.clearAllCont();			
				$(this).addClass("theworld-cont-selected");			
				$(".theworld-countries").hide();
				$("#theworld-countries-chinaasia").fadeIn();
			}
		);			
		
		
		
		

	
	},
	
	slide: function(navigation_id, pad_out, pad_in, time, multiplier) {
		
		// creates the target paths
		var list_elements = navigation_id + " li";
		var link_elements = list_elements + " a";
		
		// initiates the timer used for the sliding animation
		var timer = 0;
		
		// creates the slide animation for all list elements 
		$(list_elements).each(function(i)
		{
			// margin left = - ([width of element] + [total vertical padding of element])
			$(this).css("margin-left","-250px");
			// updates timer
			timer = (timer*multiplier + time);
			$(this).animate({ marginLeft: "0" }, timer);
			$(this).animate({ marginLeft: "10px" }, timer);
			$(this).animate({ marginLeft: "0" }, timer);
		});
	
		// creates the hover-slide effect for all link elements 		
		$(link_elements).each(function(i)
		{
			$(this).hover(
			function()
			{
				$(this).animate({ paddingLeft: pad_out }, 100);
			},		
			function()
			{
				$(this).animate({ paddingLeft: pad_in }, 50);
			});
		});
		
		
	},
	
	
	pngfix: function() {	
		jQuery(function($) {
			 //$("img").pngfix();
		});	
	},
	
	sifr: function() {
		
	//<![CDATA[
		//jQuery('h2').sifr( { strSWF: '/sifr/serifblack.swf', strColor: '#000000' } );
	//]]>
			
		
	},
	
	
	cites: function() {
		
		if (!jQuery.browser["msie"])
		{
			$('#cite').append('<img src="http://www.thedmcdirectory.com/wp-content/themes/tdd/images/cite2.png" alt="" width="400" height="19" />');
			$('#cite').append('<img src="http://www.thedmcdirectory.com/wp-content/themes/tdd/images/cite3.png" alt="" width="400" height="19" />');
			$('#cite').cycle('fade');
		}
	}
	  
};

// launch jQuery on domready
$(document).ready(function() {
	Site.start();	
	Site.pngfix();
	Site.sifr();
	
	if ($("#debug")) Site.debug();
	
});