var county = new Array();
county["gyor"] = {"x": 69, "y": 78, "name": "Győr-Moson-Sopron"};
county["vas"] = {"x": 5, "y": 164, "name": "Vas"};
county["veszprém"] = {"x": 102, "y": 165, "name": "Veszprém"};
county["zala"] = {"x": 3, "y": 240, "name": "Zala"};
county["somogy"] = {"x": 83, "y": 295, "name": "Somogy"};
county["komarom"] = {"x": 169, "y": 88, "name": "Komárom-Esztergom"};
county["fejer"] = {"x": 197, "y": 168, "name": "Fejér"};
county["tolna"] = {"x": 194, "y": 270, "name": "Tolna"};
county["baranya"] = {"x": 158, "y": 352, "name": "Baranya"};
county["bacskiskun"] = {"x": 281, "y": 266, "name": "Bács-Kiskun"};
county["csongrad"] = {"x": 386, "y": 288, "name": "Csongrád"};
county["bekes"] = {"x": 469, "y": 239, "name": "Békés"};
county["hajdubihar"] = {"x": 525, "y": 104, "name": "Hajdú-Bihar"};
county["jasznagykun"] = {"x": 415, "y": 155, "name": "Jász-Nagykun-Szolnok"};
county["szabolcsszatmar"] = {"x": 570, "y": 21, "name": "Szabolcs-Szatmár-Bereg"};
county["borsodabauj"] = {"x": 455, "y": -8, "name": "Borsod-Abaúj-Zemplén"};
county["heves"] = {"x": 368, "y": 56, "name": "Heves"};
county["pest"] = {"x": 272, "y": 112, "name": "Pest"};
county["nograd"] = {"x": 301, "y": 24, "name": "Nógrád"};

jQuery(function(jQuery) {
	Galleria.loadTheme('wp-content/themes/twentyten/galleria/themes/classic/galleria.classic.js');
	jQuery("#hungary-image").maphilight({'fillOpacity': 1, 'fillColor':'fe932b'});
	jQuery("#gallery-background-pic").maphilight({'fillOpacity': 1});
	if (jQuery("#webshops").length > 0) {
		jQuery("#webshops").html(jQuery("#webshops-hidden").html());
	}
	if (jQuery("#gallery-placeholder").length > 0) {
		jQuery("#gallery-placeholder").find(".folder").each(function() {
			var appendString = "";
			jQuery(this).find("span").each(function() {
					appendString +=  "<span style='display: none;'>"+jQuery(this).html()+"</span>"
			});
			jQuery(this).html(appendString + "<div class='description'>"+jQuery(this).find(".description").html()+"</div>").hide();
		});
		jQuery("#gallery-pic").html(jQuery(".gallery-links").hide().html());
		jQuery("#gallery-pic").find("li").each(function() {
			var folder = jQuery("#gallery_"+jQuery(this).find("a").attr("class").substring(13));
			var imgUrl = jQuery(folder).find("span:first").html().split("/");
			imgUrl.pop();
			imgUrl = imgUrl.join("/");

			jQuery(this).html("<div style='height: 54px;'>"+
				jQuery(this).html()+"</div><img id='img_"+jQuery(this).find("a").attr("class").substring(13)+"' src='"
					+imgUrl+"/thumbnail.jpg' width='120' height='120' /><br /><small><em>"
					+jQuery(folder).find("span").length+"db kép</em></small><br /><div style='height: 54px;'>"
					+jQuery(folder).find(".description").html()+"</div>")
					.css("width", "150px").css("height", "260px").css("border-right","1px solid lightgrey").css("border-bottom", "1px solid lightgrey")
					.css("background","transparent no-repeat url(wp-content/themes/twentyten/images/gallery-item.jpg)").css("color","white").find("div").find("a").css("color","white")
					.css("font-weight","bold");
		});
		
		// Megfelelő galéria megnyitása ha szükséges
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	 
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		if (vars['gallery_ID'] != null && vars['gallery_ID'] > 0) {
			showGallery(vars['gallery_ID']);
		}
	}
	if (jQuery(".one-column-kite").length > 0) {
		jQuery(".entry-title").css("text-align","center");
	}
	
	//init menu
	var i = 1;
	jQuery("div.menu-header").children("ul").children("li").each(function() {
		jQuery(this).children("a")
			.attr("style", "background: transparent;")
			.attr("id","yoyo-menu"+i)
			.html("");
		i++;
	});
	if (jQuery("li.current-menu-item").length > 0) {
		var menuID = jQuery("li.current-menu-item").find("a").attr("id").substr(9);
		if (menuID == "") {
			menuID = 2;
		}
		jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+menuID + ".png) no-repeat;");
	}
	jQuery("a[id^=yoyo-menu]").each(function() {
		var menuID = jQuery(this).attr("id").substr(9);
		jQuery(this).mouseenter(function(){		
			if (menuID == "") {
				menuID = 2;
			}
			jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+ menuID + ".png) no-repeat;");
		})
		.mouseleave(function() {
			var menuID = jQuery("li.current-menu-item").find("a").attr("id").substr(9);
			if (menuID == "") {
				menuID = 2;
			}
			jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+menuID + ".png) no-repeat;");
			/*
			if (jQuery("li.current-menu-item").length > 0) {
				var id = jQuery("li.current-menu-item").find("a").attr("id").substr(9);
			} else {
				var id = "none";
			}
			jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+id + ".png) no-repeat;");*/
		});
	});
	jQuery("#yoyo-menu2").next(".sub-menu").mouseenter(function() {
		jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu2.png) no-repeat;");
	})
	.mouseleave(function() {
			var menuID = jQuery("li.current-menu-item").find("a").attr("id").substr(9);
			if (menuID == "") {
				menuID = 2;
			}
			jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+menuID + ".png) no-repeat;");
			/*
			if (jQuery("li.current-menu-item").length > 0) {
			var id = jQuery("li.current-menu-item").find("a").attr("id").substr(9);
		} else {
			var id = "none";
		}
		jQuery("#access").attr("style", "background: transparent url(wp-content/themes/twentyten/images/menu/menu"+id + ".png) no-repeat;");*/
	});	
});

function toggleModells(element) {
	jQuery(element).parent().parent().find("div.more-pictures").slideToggle();
}

function switchimg(item) {
	jQuery(item).parent().parent().find(".mainimg").attr("src",jQuery(item).attr("src"));
}
						
function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+jQuery/g,"");
		if (x==c_name)
		{
			return unescape(y);
		}
	}
}

function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function checkCookie() {
	var city=getCookie("kites.hu_city");
	if (city!=null && city!="") {
		return city;
	} else {
		return "Budapest";
	}
}

function swapToCitySelect() {
	jQuery("#city-info").hide();
	jQuery("#city-selector").show().focus();
}
function swapToCityInfo() {
	jQuery("#city-info").show();
	jQuery("#city-selector").hide();
}
function showShops(element) {
	jQuery(".county").hide();
	jQuery("span#posts-placeholder-header").html(county[jQuery(element).attr("alt")]["name"] + " Megye értékesítési pontjai");
	jQuery("div#"+jQuery(element).attr("alt")).show();
	window.scrollTo(0,800);
}

function toggleWebShops() {
	if (jQuery("#webshop-title").find("span").find("img").attr("alt") == "down") {
		var src = jQuery("#webshop-title").find("span").find("img").attr("src").replace("dl_arrow2.png","ul_arrow2.png");
		jQuery("#webshop-title").find("span").find("img").attr("src", src).attr("alt","up");		
	} else {
		var src = jQuery("#webshop-title").find("span").find("img").attr("src").replace("ul_arrow2.png","dl_arrow2.png");
		jQuery("#webshop-title").find("span").find("img").attr("src", src).attr("alt","down");			
	}
	jQuery("#webshops").slideToggle();
}

function showBubble(element) {
	jQuery("#imagemap-bubble")
		.html(county[jQuery(element).attr("alt")]["name"]+" Megye<br /><span>"+jQuery("#"+jQuery(element).attr("alt")).find("div.seller").length+" értékesítési pont!<br/></span>Megtekintésükhöz kattintson!")
		.css("top",county[jQuery(element).attr("alt")]["y"]).css("left",county[jQuery(element).attr("alt")]["x"]).show();
}

function hideBubble(element) {
	jQuery("#imagemap-bubble").hide();
}

function swapDesc(item, toWhat) {
	jQuery(item).parent().css('background-image','url(wp-content/themes/twentyten/images/model-bg-'+toWhat+'.png)');
	if (toWhat == 'tech') {
		jQuery(item).parent().find(".desc").hide().next(".tech-desc").show();
		jQuery(item).parent().find(".desc-button").removeClass("selected");
		jQuery(item).parent().find(".tech-button").addClass("selected");
	} else {
		jQuery(item).parent().find(".tech-desc").hide().prev(".desc").show();	
		jQuery(item).parent().find(".desc-button").addClass("selected");
		jQuery(item).parent().find(".tech-button").removeClass("selected");
	}
}

function swapGallery(toWhat) {
	jQuery("#gallery").css('background-image','url(wp-content/themes/twentyten/images/gallery-bg-'+toWhat+'.png)');
	if (toWhat == "pic") {
		jQuery("#gallery-pic").show();
//		jQuery(".gallery-links").show();
		jQuery(".active-gallery").show();
		jQuery("#gallery-vid").hide();
		jQuery("#gallery-pic-title").addClass("selectedGalery");
		jQuery("#gallery-vid-title").removeClass("selectedGalery");
		jQuery("div[id^='panelcp_widget_']").hide();

	} else {
		jQuery("#gallery-vid").show();		
		jQuery(".gallery-pic").hide();
		jQuery("#gallery-pic-title").removeClass("selectedGalery");
		jQuery("#gallery-vid-title").addClass("selectedGalery");
		jQuery("div[id^='panelcp_widget_']").hide();

	}
}

function swapGalleryFolder(id) {
	jQuery(".selected-gallery-link").removeClass("selected-gallery-link");
	jQuery(".gallery-link_"+id).addClass("selected-gallery-link");
	var g = jQuery("#gallery_"+id);
	if (!g.hasClass("active-gallery")) {
		jQuery(".active-gallery").slideToggle().removeClass("active-gallery");
		jQuery(g).addClass("active-gallery").slideToggle();
		jQuery(".selected-gallery-image").removeClass("selected-gallery-image");
		jQuery(".gallery-foreground").css("background-image","url("+jQuery(g).find(".gallery-thumb:first").find("img").attr("src")+")");
		jQuery(".last").removeClass("last");
		jQuery(".first").removeClass("first");
		jQuery(g).find(".gallery-thumb:first").addClass("selected-gallery-image").find("img").addClass("first");;
		jQuery(g).find(".gallery-thumb:last").find("img").addClass("last");
	}

	
}

function checkArea(item) {
	jQuery("#imagemap-title").html(jQuery(item).attr("title"));
}

function unCheckArea(item) {
	jQuery("#imagemap-title").html("Vásárlás");
}

function prevPic() {
	var actImg = jQuery(".selected-gallery-image").find("img");
	var prevImg = null;
	if (jQuery(actImg).hasClass("first")) {
		prevImg = jQuery("img.last");
	} else {
		prevImg = jQuery(actImg).parent().prev(".gallery-thumb").find("img");
	}
	jQuery(actImg).parent().removeClass("selected-gallery-image");
	jQuery(prevImg).parent().addClass("selected-gallery-image");
	jQuery(".gallery-background").css("background-image", "url("+jQuery(prevImg).attr("src")+")");
	jQuery(".gallery-foreground").animate({
		opacity: 0,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-background").animate({
		opacity: 1,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-foreground").addClass("temp").removeClass("gallery-foreground");
	jQuery(".gallery-background").addClass("gallery-foreground").removeClass("gallery-background");
	jQuery(".temp").addClass("gallery-background").removeClass("temp");
}

function nextPic() {
	var actImg = jQuery(".selected-gallery-image").find("img");
	var nextImg = null;
	if (jQuery(actImg).hasClass("last")) {
		nextImg = jQuery("img.first");
	} else {
		nextImg = jQuery(actImg).parent().next(".gallery-thumb").find("img")
	}
	jQuery(actImg).parent().removeClass("selected-gallery-image");
	jQuery(nextImg).parent().addClass("selected-gallery-image");

	jQuery(".gallery-background").css("background-image", "url("+jQuery(nextImg).attr("src")+")");
	jQuery(".gallery-foreground").animate({
		opacity: 0,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-background").animate({
		opacity: 1,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-foreground").addClass("temp").removeClass("gallery-foreground");
	jQuery(".gallery-background").addClass("gallery-foreground").removeClass("gallery-background");
	jQuery(".temp").addClass("gallery-background").removeClass("temp");	
}

function changeGalleryImage(element) {
	jQuery(".selected-gallery-image").removeClass("selected-gallery-image");
	jQuery(element).addClass("selected-gallery-image");
	jQuery(".gallery-background").css("background-image", "url("+jQuery(element).find("img").attr("src")+")");	
	jQuery(".gallery-foreground").animate({
		opacity: 0,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-background").animate({
		opacity: 1,
	}, 1000, function() {
		// Animation complete.
	});
	jQuery(".gallery-foreground").addClass("temp").removeClass("gallery-foreground");
	jQuery(".gallery-background").addClass("gallery-foreground").removeClass("gallery-background");
	jQuery(".temp").addClass("gallery-background").removeClass("temp");
}
