$(document).ready(function(){
	
	// a fejléc navigációjának hackje
	P7_ExpMenu();
	
	// logindoboz show/hide
	$("#header-top-loginbox").show().hide();
	$("#menu_login").click(function () {
		$("#header-top-idojarasbox").fadeTo("slow",0.33,function () {
			$("#header-top-loginbox").fadeIn("slow");
    });
		return false;
	});
	
	// vezércikk rotátor
	$('#main-news').cycle({ 
    speed:       1000, 
    timeout:     6000, 
    pager:      '#main-news-rotator', 
    pagerEvent: 'click', 
		pause:			true,
    pauseOnPagerHover: false 
	});
	
	var options = {
		flvPlayer:	'http://hetnap.xnetwork.hu/templates/default/scripts/shadowbox/flvplayer.swf'
  };
  Shadowbox.init(options);
	
});

function P7_ExpMenu(){ 
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
  var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='header-navi';
     for(i=0;i<10;i++){
     	g=document.getElementById(bv+nn);
    	if(g){ lg=g.getElementsByTagName("LI");
    	if(lg){for(k=0;k<lg.length;k++){
       		lg[k].onmouseover=function(){
	        	c=this.className;cl=(c)?c+' '+cs:cs;
				this.className=cl;
			};
			lg[k].onmouseout=function(){
				c=this.className;
				this.className=(c)?c.replace(r,''):'';
			};
		}
	}
	}
	nn=i+1;
	}
}

// sima google maps + shadowbox
function Map(){

	Shadowbox.open({
		player:     'html',
		content:    '',
		height:     500,
		width:      700,
		options:    {
			onFinish: function(item){
				if(GBrowserIsCompatible()){
					var address = document.forms.utcakereso.utca_varos.value + ' ,' + document.forms.utcakereso.utca_cim.value;
					var geocoder = null;
					geocoder = new GClientGeocoder();
					
					var map = new GMap2(document.getElementById('shadowbox_content'));
					
					 if (geocoder) {
						geocoder.getLatLng(
							address,
							function(point) {
							if (!point) {
								//alert(address + " not found");
								notFound(address);
							} else {
								map.setCenter(point, 17);
								var marker = new GMarker(point);
								map.addOverlay(marker);
								//marker.openInfoWindowHtml(address);
							}
							}
						);
					}							
					
					// add some simple controls
					map.addControl(new GOverviewMapControl());
					map.enableDoubleClickZoom();
					map.enableScrollWheelZoom();
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());
					
				}
			}
		}
	});

};

// google route map + shadowbox
var gdir;
var geocoder = null;

function routeMap(){

	Shadowbox.open({
		player:     'html',
		content:    '',
		height:     500,
		width:      700,
		options:    {
			onFinish: function(item){
				 if (GBrowserIsCompatible()) {      
				 	var geocoder = null;

					geocoder = new GClientGeocoder();
					
					map = new GMap2(document.getElementById("shadowbox_content"));
					gdir = new GDirections(map, document.getElementById("shadowbox_content2"));
					
					var from = document.forms.utvonal.utvon_varos.value + ' ,' + document.forms.utvonal.utvon_cim.value;
					var to = document.forms.utvonal.utvon_varos_to.value + ' ,' + document.forms.utvonal.utvon_cim_to.value;
					
					//From hely ellenőrzés
					if (geocoder) {
						geocoder.getLatLng(
						  from,
						  function(point) {
							if (!point) {
							  //alert("'"+from+"' cím nem található1!");
							  notFound(from);
							} else {
								//To hely ellenőrzés
								if (geocoder) {
										geocoder.getLatLng(
											 to,
											 function(point) {
												if (!point) {
												  //alert("'"+to+"' cím nem található2!");
												  notFound(to);
												}
											 }
										);
								}
								//To hely ellenőrzés vége
							}
						  }
						);
					  }	
					//From hely ellenőrzés vége
					
					setDirections(from, to, "en_US");
					
					map.addControl(new GOverviewMapControl());
					map.enableDoubleClickZoom();
					map.enableScrollWheelZoom();
					map.addControl(new GSmallMapControl());
					map.addControl(new GMapTypeControl());
				
				}
			}
		}
	});

};

function setDirections(fromAddress, toAddress, locale){
   
	gdir.load("from: " + fromAddress + " to: " + toAddress,{ "locale": locale }); }

	function handleErrors(){
	 if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		 alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	 else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		 alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	 
	 else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		 alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		 
	 else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		 alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
	
	 else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		 alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		
	 else alert("An unknown error occurred.");
	   
}

//google maps hibaüzenet dobás
function notFound(address){

    Shadowbox.open({
        player:     'html',
        content:    '<div style="color:white;padding:5px;text-align:center;font-family: "Arial", Helvetica, sans-serif;">A megadott tartalom nem található!<br>('+address+')</div>',
        height:     100,
        width:      300,
		title:      'Hiba'
    });

};




