/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -10;
		yOffset = 15;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("area.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		
		if(this.t == '' && this.alt == ''){ return;} //when no text is supplied exit
		var c = (this.t != "") ? "<br />" + this.t : "";
		$("body").append("<p id='preview'>" + this.alt +  c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
	    this.style.height= "2px";				
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$(".preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			

		

};




this.selectMaps = function() {
	$('#topCountries').change(function(){

if($(this).val() == 'Germany'){


    if($('#WorldMapImage').is('.open')){
            $('#WorldMapImage').hide('slide', null, 300, function(){$('#DEMapImage').show('slide', null, 300)});
            $('#WorldMapImage').removeClass("open").addClass('closed');

    }
    else if($('#USMapImage').is('.open')){
            $('#USMapImage').hide('slide', null, 300, function(){$('#DEMapImage').show('slide', null, 300)});
            $('#USMapImage').removeClass("open").addClass('closed');

    
    
    }
    
    
    $('#DEMapImage').removeClass("closed").addClass('open');    


    	
}
else if($(this).val() == 'United States'){

     if($('#WorldMapImage').is('.open')){
            $('#WorldMapImage').hide('slide', null, 300, function(){$('#USMapImage').show('slide', null, 300)});
            $('#WorldMapImage').removeClass("open").addClass('closed');

    }
    else if($('#DEMapImage').is('.open')){
            $('#DEMapImage').hide('slide', null, 300, function(){$('#USMapImage').show('slide', null, 300)});
            $('#DEMapImage').removeClass("open").addClass('closed'); 
    
    }

    $('#USMapImage').removeClass("closed").addClass('open');

}
else{

     if($('#USMapImage').is('.open')){
            $('#USMapImage').hide('slide', null, 300, function(){$('#WorldMapImage').show('slide', null, 300)});
            $('#USMapImage').removeClass("open").addClass('closed');

    }
    else if($('#DEMapImage').is('.open')){
            $('#DEMapImage').hide('slide', null, 300, function(){$('#WorldMapImage').show('slide', null, 300)});
            $('#DEMapImage').removeClass("open").addClass('closed'); 
    
    }

    $('#WorldMapImage').removeClass("closed").addClass('open');



}
/*$.ajax({
			url: ('seite_mit_dem_script.php'),
			data: 'id=' + $(this).val(),
			type: 'GET',
			timeout: 3000,
			dataType: 'json',
			error: function() {
				alert('Error loading json data!');
			},
			success: function(json){
				var output = '';
				for (p in json) {
					output += '<option value=\"' + json[p].oV + '\">' + json[p].oT + '</option>\n';
				}
				$('#typ').html(output);
			}
		})*/
	});
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
	selectMaps();
});

