$(document).ready(function() {
	
	jQuery.fn.exists = function(){return jQuery(this).length>0;}

	// SVG
	if ($('#svg').get() != "") {
		
		var ie = false;
		if(navigator.userAgent != undefined) {
			var agent = navigator.userAgent;
			if(agent.indexOf('MSIE') > 0 && !(agent.indexOf('MSIE 9') > 0)) {
				ie = true;
			}
		}
		
		if (!ie) {
			document.getElementById('svg').style.display = 'block';
		}
		
	}
	
	// Auto completion
	$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";
			$.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
				}
				self._renderItem( ul, item );
			});
		}
	});
	
	// Modebar (Clips)
	$('.modebar li').mouseenter(function() {
		$(this).addClass('hover');
	});
	$('.modebar li').mouseleave(function() {
		$(this).removeClass('hover');
	});
	
	// Hitlistbar
	$('.hitlistbar li').mouseenter(function() {
		$(this).addClass('hover');
	});
	$('.hitlistbar li').mouseleave(function() {
		$(this).removeClass('hover');
	});
	$('.hitlistbar li').click(function() {
		$('.hitlistbar li').each(function() {
			$(this).removeClass('cur');
		});
		$(this).addClass('cur');
		
		var hitlist = $(this).attr('id').replace('hitlist_','');
			
		$('#hitlist_tables .hitlist').each(function() {
			$(this).hide();
		});
		
		$('#hitlist_tables .'+hitlist).show();
		
	});
	
	// Parambar
	$('.parambar li').mouseenter(function() {
		$(this).addClass('hover');
	});
	$('.parambar li').mouseleave(function() {
		$(this).removeClass('hover');
	});
	$('.parambar li').click(function() {
		$('.parambar li').each(function() {
			$(this).removeClass('cur');
		});
		$(this).addClass('cur');
		
		var param = $(this).attr('id').replace('param_','');
		
		var hash = true;
		if (param == 'ski_snow_valley' || (param == 'tt' && $('.parambar #param_pp0').attr('id') == 'param_pp0')) {
			hash = false;
		}

		if (hash) {
			location.hash = param;
		} else {
			//location.hash = '';
		}
		
		$('.timebar a').each(function() {
			var hashpos = $(this).attr('href').indexOf('#');
			if (!hash) {
				if (hashpos > 0) {
					$(this).attr('href', ($(this).attr('href').substr(0, hashpos)));
				}
			}
			else {
				if (hashpos > 0) {
					$(this).attr('href', ($(this).attr('href').substr(0, hashpos) + '#' + param));
				}
				else {
					$(this).attr('href', ($(this).attr('href') + '#' + param));
				}
			}
		});
		
		if(param == 'ffx') {
			$('#map .sym').hide();
			$('#map .dd').show();
		} else {
			$('#map .sym').show();
			$('#map .dd').hide();
		}	
		$('.map-tmp-tt-span').hide();
		$('.map-tmp-hi-span').hide();
		$('#map .parameter').each(function() {
			$(this).hide();
		});
		
		
		if(param == 'tt') {
			$('#map span .tx').show();
			$('#map span .tn').show();
			if($('#map span .tn').exists())
				$('.map-tmp-tt-span').css('display','block');
			$('.map-tmp-hi-span').hide();
		} else if(param == 'hi') {
			//$('#map  .hix').show();
			//$('#map  .hin').show();
			$('#map span .hin').show();
			$('#map span .hix').show();
			if($('#map span .hix').exists())
				$('.map-tmp-hi-span').css('display','block');
			$('.map-tmp-tt-span').hide();
			//$('#map span .hin').css('display','inline');
			//$('#map span .hix').css('display','inline');
		}
		$('#map  .'+param).show();
	});
	
	if($('.parambar #param_pp0').attr('id') == 'param_pp0') {
		var hash = location.hash.replace('#','');
		if(hash) {
			
			//$('.map-tmp-tt-span').hide();
			//$('.map-tmp-hi-span').hide();
			//$('#map .parameter').each(function(){
			//	$(this).hide();
			//});
			$('#param_'+hash).trigger('click');
		} else {
			$('#param_tt').trigger('click');
		}
	} 
	
	if ($('#param_ski_snow_valley').attr('id') == 'param_ski_snow_valley') {
		var hash = location.hash.replace('#','');
		if (!hash) {
			hash = 'ski_snow_valley';
		}
		$('#param_'+hash).trigger('click');
		$('#map .parameter').each(function(){
			$(this).hide();
		});
		$('#map .'+hash).show();
	}
	
	// UVbar
	$('.uvbar li').mouseenter(function() {
		$(this).addClass('hover');
	});
	$('.uvbar li').mouseleave(function() {
		$(this).removeClass('hover');
	});
	
	// Timebar
	$('.timebar li, .timebar .time').mouseenter(function() {
		$(this).addClass('hover');
	});
	$('.timebar li, .timebar .time').mouseleave(function() {
		$(this).removeClass('hover');
	});
	
	// Weather Widget
	$('#weatherwidget_agreement').change(function() {
		if ($('#weatherwidget_agreement:checked').val() !== undefined) {
			$('.weatherwidget .code').show();
		} else {
			$('.weatherwidget .code').hide();
		}
	});
	
	$('.activity .more').click(function() {
		$('.over15').show();
		$('.activity .more').hide();
		$('.activity .less').show();
	});
	$('.activity .less').click(function() {
		$('.over15').hide();
		$('.activity .less').hide();
		$('.activity .more').show();
		
	});
	
	// My weather
	var found = false;
	var cookie = new Array();
	var homeplace = 0;
	var snow = false;
	
	if (document.cookie) {
		var cookies = document.cookie.split(';');

		for (var i = 0; i < cookies.length; i++) {
			cookie = cookies[i].split('=');
			if (cookie[0].replace(' ','') == 'home-place') {
				found = true;
				homeplace = cookie[1];
			} else if(cookie[0].replace(' ','') == 'snow') {
				snow = true;
			}
		}
	}


	//if(!snow && $('.content #myweather_container_new').exists()) {
	//	document.cookie = 'snow=1';
	//	$('#snowlayer').show();
	//}

	if(!found) {
		cookie = 0;
	} else {
		cookie = homeplace;
	}
	
	
	//$.get('/de/request/myweather/'+parseInt(cookie,10)+'/', function(data) {
	//	$('#myweather_container').html(data);
	//	$("#myweather-tabs").tabs();
	//	$('#myweather-more').attr('href',$('#myweather-link').val());
	//});
	
	if(cookie!=0) {
		var sidebar = '';
		if($('#content_sidebar #myweather_container_new').attr('id') != undefined) {
			sidebar = '?sidebar=true';
		}
		$.get('/de/request/myweather/'+parseInt(cookie,10)+'/'+sidebar, function(data) {
			$('#myweather_container_new').show();
			$('#myweather_container_new').html(data);
			//$("#myweather_tabs").tabs();
			//$('#myweather-more').attr('href',$('#myweather-link').val());
		});
	}
	
	var cache = {},
		lastXhr;
	$( "#place_search" ).catcomplete({
		minLength: 3,
		source: function( request, response ) {
			var term = request.term;
			var parent_id = request.id;
			if ( term in cache ) {
				response( cache[ term ] );
				return;
			}
			
			var res = '';
			if($( "#place_search_section" ).val() != '/de/') {
				res = '?res='+$( "#place_search_section" ).val();
			}
			
			
			lastXhr = $.getJSON( "/de/request/search/"+res, request, function( data, status, xhr ) {
				cache[ term ] = data;
				if ( xhr === lastXhr ) {
					response( data );
				}
			});
		},
		select: function( event, ui ) {
			//$( "#place_search" ).val( ui.item.label );
			document.location.href=ui.item.link.replace('/de/',$( "#place_search_section" ).val());
			//$( "#home-id" ).val( ui.item.value );
			return false;
		},
		focus: function( event, ui ) {
			
			return false;
		}
	});
	
	var cache_snow = {},
		lastXhr_snow;
	$( "#snow_search" ).catcomplete({
		minLength: 3,
		source: function( request, response ) {
			var term = request.term;
			var parent_id = request.id;
			if ( term in cache_snow ) {
				response( cache_snow[ term ] );
				return;
			}
			
			var res = '?res=snow';
			lastXhr_snow = $.getJSON( "/de/request/search/"+res, request, function( data, status, xhr ) {
				cache_snow[ term ] = data;
				if ( xhr === lastXhr_snow ) {
					response( data );
				}
			});
		},
		select: function( event, ui ) {
			$( "#snow_search" ).val( ui.item.label );
			$('#snow_search_link').val(ui.item.link);
			//$( "#home-id" ).val( ui.item.value );
			return false;
		},
		focus: function( event, ui ) {
			
			return false;
		}
	});

	$(".snow_close").click(function() {
		$('#snowlayer').hide();
	});

	$(".snow_yes, .snow_no").click(function() {
		if($('#snow_search_link').val()=="") {
			alert('Bitte wählen Sie Ihren Ort aus!');
		} else {
			document.location.href=$('#snow_search_link').val()+'/xmas';
		}
	});
	
	// Weather center
	$("#weathercenter-tabs").tabs();
	
	// Media
	$("#media-tabs").tabs();
	$(".gallery_photo:first").show();
	$(".gallery_photo:first").addClass('cur');
	$("#media-tabs-photos .next").click(function() {

		if($('#photos_container_start').exists()) {
			
			$("#media_photos").trigger('click');

		} else {

			var element = $(".gallery_photo.cur");
			element.hide();
			element.removeClass('cur');
			if(element.next().is('a')) {
				element.next().show();
				element.next().addClass('cur');
			} else {
				$(".gallery_photo:first").show();
				$(".gallery_photo:first").addClass('cur');
			}

		}
	});
	$("#media-tabs-photos .prev").click(function() {

		if($('#photos_container_start').exists()) {

			$("#media_photos").trigger('click');

		} else {

			var element = $(".gallery_photo.cur");
			element.hide();
			element.removeClass('cur');
			if(element.prev().is('a')) {
				element.prev().show();
				element.prev().addClass('cur');
			} else {
				$(".gallery_photo:last").show();
				$(".gallery_photo:last").addClass('cur');
			}

		}
	});
	
	
	$("#media-tabs-webcams .next").click(function() {
		var element = $(".gallery_webcam.cur");
		element.hide();
		element.removeClass('cur');
		if(element.next().is('a')) {
			element.next().show();
			element.next().addClass('cur');
		} else {
			$(".gallery_webcam:first").show();
			$(".gallery_webcam:first").addClass('cur');
		}
	});
	$("#media-tabs-webcams .prev").click(function() {
		var element = $(".gallery_webcam.cur");
		element.hide();
		element.removeClass('cur');
		if(element.prev().is('a')) {
			element.prev().show();
			element.prev().addClass('cur');
		} else {
			$(".gallery_webcam:last").show();
			$(".gallery_webcam:last").addClass('cur');
		}
	});
	
	$("#media_webcams").click(function() {

		if($('#webcams_container').html() == "") {
			
			$("#media-tabs-webcams .next").hide();
			$("#media-tabs-webcams .prev").hide();
			
			$('#webcams_container').html('<img class="loading" src="/assets/img/design/loading.gif" />');
		
			$.get('/de/request/webcams/', function(data) {
				$('#webcams_container').html(data);
				$(".gallery_webcam:first").show();
				$(".gallery_webcam:first").addClass('cur');
				$("#media-tabs-webcams .next").show();
				$("#media-tabs-webcams .prev").show();
			});
		
		}
	});	
	
	$("#media_photos").click(function() {

		if($('#photos_container_start').exists()) {
			
			$("#media-tabs-photos .next").hide();
			$("#media-tabs-photos .prev").hide();
			
			$('#photos_container').html('<img class="loading" src="/assets/img/design/loading.gif" />');
		
			$.get('/de/request/photos/', function(data) {
				$('#photos_container').html(data);
				$(".gallery_photo:first").show();
				$(".gallery_photo:first").addClass('cur');
				$("#media-tabs-photos .next").show();
				$("#media-tabs-photos .prev").show();
				$("#media-tabs-photos .next").trigger('click');
			});
		
		}
	});	
	
	$('.weather_search').submit(function() {
		$('#place_search_submit').trigger('click');
		return false;
	});
	
	$('#snow_search').focus(function() {
		if($(this).val() == $('#snow_search_default').val()) {
			$(this).val('');
		}
	});
	
	$('#snow_search').blur(function() {
		if($(this).val() == '') {
			$(this).val($('#snow_search_default').val());
		}
	});
	
	$('#place_search').focus(function() {
		if($(this).val() == $('#place_search_default').val()) {
			$(this).val('');
		}
	});
	
	$('#place_search').blur(function() {
		if($(this).val() == '') {
			$(this).val($('#place_search_default').val());
		}
	});
	
	$('.wiki_search').submit(function() {
		$('#wiki_search_submit').trigger('click');
		return false;
	});
	
	$('#wiki_search').focus(function() {
		if($(this).val() == $('#wiki_search_default').val()) {
			$(this).val('');
		}
	});
	
	$('#wiki_search').blur(function() {
		if($(this).val() == '') {
			$(this).val($('#wiki_search_default').val());
		}
	});
	
	$('#search_result').dialog({autoOpen: false, modal: true, width: 300, height: 400, resizable: false });

	$('#place_search').keydown(function(event) {
        if (event.keyCode == 13) {
            $('#place_search_submit').trigger('click');
            return false;
         }
    });

	$('#wiki_search').keydown(function(event) {
        if (event.keyCode == 13) {
            $('#wiki_search_submit').trigger('click');
            return false;
         }
    });

	$('#place_search_submit').click(function() {
		$( "#place_search" ).catcomplete('close');
		$( "#place_search" ).css('background','white');
		$('#search_redirect').val('');
		if ($('#place_search').val() != '') {
			$('#place_search_submit').attr('src','/assets/img/design/loading.gif');
			
			var section = '';
			if($( "#place_search_section" ).val() != '/de/') {
				section = '&section='+$( "#place_search_section" ).val();
			}
			
			$.get('/de/request/searchbox/?place_search=' + $('#place_search').val() +''+section, function(data){
				$( "#place_search" ).catcomplete('close');
				$( "#place_search" ).css('background','');
				$('#search_result').html(data);
				if ($('#search_redirect').val() != '' && $('#search_redirect').val() != undefined) {
					//$(location).attr('href',$('#search_redirect').val());
					document.location.href = $('#search_redirect').val();
				} else {
					$('#search_result').dialog('open');
					$('#place_search_submit').attr('src','/assets/img/icons/general/search.png');
				}
			});
		}
		return false;
	});
	
	$('#wiki_search_submit').click(function() {
		if ($('#wiki_search').val() != '') {
			$('#wiki_search_submit').attr('src','/assets/img/design/loading.gif');
			
			$.get('/de/request/searchbox/?wiki_search=' + $('#wiki_search').val(), function(data){
				$('#search_result').html(data);
				if ($('#search_redirect').val() != '' && $('#search_redirect').val() != undefined) {
					//$(location).attr('href',$('#search_redirect').val());
					document.location.href = $('#search_redirect').val();
				} else {
					$('#search_result').dialog('open');
					$('#wiki_search_submit').attr('src','/assets/img/icons/general/search.png');
				}
			});
		}
		return false;
	});
	
	// Locationbar
	$('.locationbar span').mouseenter(function() {
		if ($(this).next().html() != '') {
			$(this).next().show();
		}
	});
	$('.locationbar span').mouseleave(function() {
		$(this).next().hide();
	});
	$('.locationbar .list').mouseenter(function() {
		$(this).show();
	});
	$('.locationbar .list').mouseleave(function() {
		$(this).hide();
	});
	
	
	//Navigation
	$('.mainmenu-home-country').mouseenter(function() {
	  	$('#mainmenu-home-country-wrapper').show();
	});
	$('.mainmenu-home-country').mouseleave(function() {
	  	$('#mainmenu-home-country-wrapper').hide();
	});
	$('#mainmenu-home-country-wrapper').mouseenter(function() {
		$(this).show();
	});
	$('#mainmenu-home-country-wrapper').mouseleave(function() {
		$(this).hide();
	});
	
	$('.mainmenu-world').mouseenter(function() {
	  	$('#mainmenu-world-wrapper').show();
	});
	$('.mainmenu-world').mouseleave(function() {
	  	$('#mainmenu-world-wrapper').hide();
	});
	$('#mainmenu-world-wrapper').mouseenter(function() {
		$(this).show();
	});
	$('#mainmenu-world-wrapper').mouseleave(function() {
		$(this).hide();
	});
	
	$('.mainmenu-germany').mouseenter(function() {
	  	$('#mainmenu-germany-wrapper').show();
	});
	$('.mainmenu-germany').mouseleave(function() {
	  	$('#mainmenu-germany-wrapper').hide();
	});
	$('#mainmenu-germany-wrapper').mouseenter(function() {
		$(this).show();
	});
	$('#mainmenu-germany-wrapper').mouseleave(function() {
		$(this).hide();
	});
	
	$('.mainmenu-uv').mouseenter(function() {
	  	$('#mainmenu-uv-wrapper').show();
	});
	$('.mainmenu-uv').mouseleave(function() {
	  	$('#mainmenu-uv-wrapper').hide();
	});
	$('#mainmenu-uv-wrapper').mouseenter(function() {
		$(this).show();
	});
	$('#mainmenu-uv-wrapper').mouseleave(function() {
		$(this).hide();
	});
	
	$('.mainmenu-webcams').mouseenter(function() {
	  	$('#mainmenu-webcams-wrapper').show();
	});
	$('.mainmenu-webcams').mouseleave(function() {
	  	$('#mainmenu-webcams-wrapper').hide();
	});
	$('#mainmenu-webcams-wrapper').mouseenter(function() {
		$(this).show();
	});
	$('#mainmenu-webcams-wrapper').mouseleave(function() {
		$(this).hide();
	});
	
	$('#msg_blogsuggestion').focus(function() {
		if($(this).val() == $('#msg_blogsuggestion_default').val()) {
			$(this).val('');
		}
	});
	$('#msg_blogsuggestion').blur(function() {
		if($(this).val() == '') {
			$(this).val($('#msg_blogsuggestion_default').val());
		}
	});
	
	$('#msg_feedback').focus(function() {
		if($(this).val() == $('#msg_feedback_default').val()) {
			$(this).val('');
		}
	});
	$('#msg_feedback').blur(function() {
		if($(this).val() == '') {
			$(this).val($('#msg_feedback_default').val());
		}
	});
	
	
	window.fbAsyncInit = function() {
    FB.init({appId: '102735713115603', status: true, cookie: true,
             xfbml: true});
  		};
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/de_DE/all.js';
    document.getElementById('fb-root').appendChild(e); 
  }());
  
  //Hide 'contentad' if no ad was delivered
  if($('#contentad a img:first-child').attr('src') == 'http://ad.adworx.at/RealMedia/ads/Creatives/default/empty.gif') {
	  $('#contentad').hide();
  }
  
  //Forecast-Text [more|less]
  $('#forecast_text_more_link').click(function(){
  	$('#forecast_text_less').hide(); $('#forecast_text_more').show();
  });

  $('#forecast_text_less_link').click(function(){
  	$('#forecast_text_less').show(); $('#forecast_text_more').hide();
  });
  
  //Hide border-radius-hack-images for ie
  if($.browser.msie) { $('.png-border-radius').hide(); }
  
  //Poll
  if($('#poll-wrapper').exists()) {
    $.get('/de/request/poll/', function(data) {
  	  $('#poll-wrapper').show();
  	  $('#poll-wrapper').html(data);
    });
  }
  
  //center mappoint-links
  $('.mappointname').each(function(){
		widthOfLink = $(this).width();
		widthOfBox = 62;
	    if(widthOfLink>widthOfBox) {
	        $(this).css('margin-left', (widthOfLink-widthOfBox)/2*-1);
	    }
  });
  
});//end of document-ready-function

function myBioWeather() {
	
	var found = false;
	var cookie = new Array();
	
	if (document.cookie) {
		var cookies = document.cookie.split(';');
	
		for (var i = 0; i < cookies.length; i++) {
			cookie = cookies[i].split('=');
			if (cookie[0].replace(' ','') == 'home-place') {
				found = true;
				break;
			}
		}
	}
	
	if(!found) {
		cookie = 0;
	} else {
		cookie = cookie[1];
	}
	
	if(cookie!=0) {
		$.get('/de/request/widget/detailbio/'+parseInt(cookie,10)+'/', function(data) {
			$(data).insertBefore('#contentad');
		});
		$.get('/de/request/widget/detailpollen/'+parseInt(cookie,10)+'/', function(data) {
			$(data).insertAfter('#contentad');
		});
	}
}

//myweather
function myweather_deleteCookie() {
	location.href='/de/?home-id=';
	$('#myweather_container_new').hide();
}

// Counter
function counter(type, object) {
	$.get('/de/request/counter/'+type+'/'+object+'/', function(data) {});
}


// Facebook Kommentar veröffentlichen
function publishComment() {
	var msg = $('#comment_msg').val();
  	if(msg.length > 0) {
	
  	 FB.ui(
	   {
	     method: 'stream.publish',
	     message: msg,
	     attachment: {
	       name: document.title,
	       description: ( $('meta[name=description]').attr("content") ),
	       href: location.href,
		   media:[{'type':'image','src':$('#fb_image').val(),'href':location.href}]
	     },
	     user_message_prompt: 'Teile deinen Kommentar auf Facebook'
	   },
	   function(response) {
	     if (response && response.post_id) {
	       //alert('Post was published.');
	     } else {
	       //alert('Post was not published.');
	     }
	     document.getElementById('commentform').submit();
	   }
	 );
  	}
}

function getPreviewPlot(p1data, p2data, p3data, p4data, themode) {	
	$.jqplot.config.enablePlugins = true;

    plot1_data = p1data;

    var plot1_min, plot1_max;
    for (var i = 0; i < plot1_data.length; i++){
		if(i == 0) {
			plot1_min = plot1_data[i][1];
			plot1_max = plot1_data[i][1];
		}	
        
        if(plot1_data[i][1] > plot1_max)
            plot1_max = plot1_data[i][1];
        if(plot1_data[i][1] < plot1_min)
            plot1_min = plot1_data[i][1]; 
    }
    
    //new
    if(Math.round(plot1_min)<0) {
        var line_zero = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
        var zero_line_active = true;
    } else {
    	var line_zero = [];
    	var zero_line_active = false;
    }
    	
    plot1_min = Math.round(plot1_min-3);
    plot1_max = Math.round(plot1_max+3);
    while((plot1_max-plot1_min)%6!=0)
    	plot1_max++;
    
    if(zero_line_active) {
		plot1 = $.jqplot(themode + '_chart_temperature', [line_zero, plot1_data], {    
			highlighter: {
		    	lineWidthAdjust: 2.5,
		    	fadeTooltip: true,
				tooltipAxes: 'y',
				tooltipLocation: 'w'
	   	 	},
			seriesDefaults: {
				shadow: true,
				shadow: false,
				markerOptions: {
		        	show: false
				},
				pointLabels:{show:false}
			},
			seriesColors: [ "#85b9e0", "#ef7900" ], 
			gridPadding: {top:0, right:0, bottom:0, left:0},
			grid: {
		    	drawGridLines: true,
	 			background: '#6495CD',
				gridLineColor: '#85b9e0',
				borderWidth: 0,
		    	shadow: false
			},
			series: [{
			pointLabels:{
		   		show:false
		   }
		}],
		    axes: {
		        xaxis: {
		            ticks:[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
		            renderer: $.jqplot.CategoryAxisRenderer,
					showTicks: false
		        },
				yaxis:{
					min:(plot1_min-3),
					max:(plot1_max+3),
					numberTicks:7,
					showTicks: true,
					showTickMarks: false,
					tickOptions: { formatString: '%d°C' }
				}
		    }
		});
	} else {
		plot1 = $.jqplot(themode + '_chart_temperature', [plot1_data], {    
			highlighter: {
		    	lineWidthAdjust: 2.5,
		    	fadeTooltip: true,
				tooltipAxes: 'y',
				tooltipLocation: 'w'
	   	 	},
			seriesDefaults: {
				shadow: true,
				shadow: false,
				markerOptions: {
		        	show: false
				},
				pointLabels:{show:false}
			},
			seriesColors: [ "#ef7900", "#85b9e0" ], 
			gridPadding: {top:0, right:0, bottom:0, left:0},
			grid: {
		    	drawGridLines: true,
	 			background: '#6495CD',
				gridLineColor: '#85b9e0',
				borderWidth: 0,
		    	shadow: false
			},
			series: [{
			pointLabels:{
		   		show:false
		   }
		}],
		    axes: {
		        xaxis: {
		            ticks:[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
		            renderer: $.jqplot.CategoryAxisRenderer,
					showTicks: false
		        },
				yaxis:{
					min:(plot1_min-3),
					max:(plot1_max+3),
					numberTicks:7,
					showTicks: true,
					showTickMarks: false,
					tickOptions: { formatString: '%d°C' }
				}
		    }
		});
	}
    
    var plot4_min, plot4_max;
    for (var i = 0; i < p4data.length; i++){
		if(i == 0) {
			plot4_min = p4data[i][1];
			plot4_max = p4data[i][1];
		}	
        
        if(p4data[i][1] > plot4_max)
        	plot4_max = p4data[i][1];
        if(p4data[i][1] < plot4_min)
        	plot4_min = p4data[i][1]; 
    }
    
    //new
    plot4_min = Math.round(plot4_min-3);
    plot4_max = Math.round(plot4_max+3);
    while((plot4_max-plot4_min)%6!=0)
    	plot4_max++;
    
    plot4 = $.jqplot(themode + '_chart_wind', [p4data], {
		highlighter: {
        	lineWidthAdjust: 2.5,
        	fadeTooltip: true,
			tooltipAxes: 'y',
			tooltipLocation: 'w'
   	 	},
		seriesDefaults: {
			shadow: true,
			color: '#1E61A0',
			shadow: false,
			markerOptions: {
            	show: false
			}
		},	
		gridPadding: {top:0, right:0, bottom:0, left:0},
		grid: {
        	drawGridLines: true,
 			background: '#7AA6DF',
			gridLineColor: '#85b9e0',
			borderWidth: 0,
        	shadow: false
		},
		series: [{
			pointLabels:{
		   		show:false
		   }
		}],
        axes: {
            xaxis: {
                ticks:[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
                renderer: $.jqplot.CategoryAxisRenderer,
				showTicks: false
            },
			yaxis:{
				min:(plot4_min),
				max:(plot4_max),
				numberTicks:7,
				showTicks: true,
				showTickMarks: false,
				tickOptions: { formatString: '%dkm/h' }
			}
        }
    });

    plot2_data = p2data;
    var plot2_min = 0, plot2_max;
    for (var i = 0; i < plot2_data.length; i++){
		if(i == 0) {
			plot2_max = plot2_data[i][1];
		}	
        
        if(plot2_data[i][1] > plot2_max)
            plot2_max = plot2_data[i][1]; 
    }
    
    //new
    plot2_max = Math.round(plot2_max+3);
    if(plot2_max<6) {
    	plot2_max = 6;
    } else {
    	while(plot2_max%6!=0)
    		plot2_max++;
    }
    
    plot3 = $.jqplot(themode + '_chart_precipitation', [plot2_data], {    
    	highlighter: { show: false },
		seriesDefaults: {
            renderer: $.jqplot.BarRenderer,
			color: '#1C5C96',
			shadow: false,
            rendererOptions: {
                barPadding: 0,
                barMargin: 2
            }
        },
		gridPadding: {top:0, right:0, bottom:0, left:0},
		grid: {
        	drawGridLines: true,
 			background: '#74A1D8',
			gridLineColor: '#a6c9e3',
			borderWidth: 0,
        	shadow: false
		},
		series: [{
			pointLabels:{
		   		show:false
		   }
		}],
        axes: {
            xaxis: {
                ticks:[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
                renderer: $.jqplot.CategoryAxisRenderer,
				showTicks: false
            },
			yaxis:{
				min:plot2_min,
				max:plot2_max,
				numberTicks:7,
				showTicks: true,
				showTickMarks: false,
				tickOptions: { formatString: '%dmm/6h' }
			}
        }
    });

    var plot3_min = 0, plot3_max = 6;
    for (var i = 0; i < p3data.length; i++){
		if(p3data[i][1] > plot3_max)
            plot3_max = p3data[i][1]; 
    }
    
    //new
    plot3_max = Math.round(plot3_max);
    while(plot3_max%6!=0)
    	plot3_max++;
    
	line1 = p3data;
    plot3 = $.jqplot(themode + '_chart_sun', [line1], {    
		highlighter: { show: false },
        seriesDefaults: {
            renderer: $.jqplot.BarRenderer,
			color: '#EFC62E',
			shadow: false,
            rendererOptions: {
                barPadding: 0,
                barMargin: 2
            }
        },
		gridPadding: {top:0, right:0, bottom:0, left:0},
		grid: {
        	drawGridLines: true,
 			background: '#8CB4E8',
			gridLineColor: '#a6c9e3',
			borderWidth: 0,
        	shadow: false
		},
		series: [],
        axes: {
            xaxis: {
            	ticks:[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                renderer: $.jqplot.CategoryAxisRenderer,
				showTicks: false
            },
			yaxis:{
				min:plot3_min,
				max:(plot3_max),
				numberTicks:7,
				showTicks: true,
				showTickMarks: false,
				tickOptions: { formatString: '%dh' }
			}
        }		
    });
}

function switchDiagram(mode) {
	$('#'+mode+'_diagram').css('display', 'block');
	if(mode=='trend'){
		$('#preview_diagram').css('display', 'none');
		/*$('#preview_diagram_link').addClass('switch-diagram');
		$('#preview_diagram_link').removeClass('switch-diagram-active');
		$('#trend_diagram_link').removeClass('switch-diagram');
		$('#trend_diagram_link').addClass('switch-diagram-active');*/
		
		$('#trend_diagram_link').addClass('active');
		$('#preview_diagram_link').removeClass('active');
		
	} else {
		$('#trend_diagram').css('display', 'none');
		//$('#trend_diagram_link').addClass('switch-diagram');
		$('#trend_diagram_link').removeClass('active');
		$('#preview_diagram_link').addClass('active');
		//$('#preview_diagram_link').removeClass('switch-diagram');
		//$('#preview_diagram_link').addClass('switch-diagram-active');
	}
}

