//
// main.js
//
jQuery(document).ready(function($) {
	$("div#navigation ul li").hover(
		function() {$("ul", this).css("display", "block");},
		function() {$("ul", this).css("display", "none");}
	);

	$(".dropdown img.flag").addClass("flagvisibility");

	$(".dropdown dt a").click(function() {
		$(".dropdown dd ul").toggle();
	});

	$(".dropdown dd ul li a").click(function() {
		var text = $(this).html();
		$(".dropdown dt a span").html(text);
		$(".dropdown dd ul").hide();
		$("#result").html("Selected value is: " + getSelectedValue("sample"));
	});

	function getSelectedValue(id) {
		return $("#" + id).find("dt a span.value").html();
	}

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("dropdown"))
			$(".dropdown dd ul").hide();
	});

	if ($("#tool-location").length > 0) {
		$("#tool-location").msDropDown();
	}

	$(".default-text").focus(function(srcc) {
		if ($(this).val() == $(this)[0].title) {
			$(this).removeClass("defaultTextActive");
			$(this).val("");
		}
	});

	$(".default-text").blur(function() {
		if ($(this).val() == "") {
			$(this).addClass("defaultTextActive");
			$(this).val($(this)[0].title);
		}
	});

	$(".default-text").blur();

	ph_tipTip();
});

function ph_showSubnav(pid) {
	jQuery('#subnav'+pid).each(function(i,v) {
		ph_removeAllOtherSubnavs(pid);
		var to = parseInt(jQuery(this).attr("subnavto"));
		if (to>0) {
			clearTimeout(to);
			jQuery(this).attr("subnavto", "-1");
		}
		var p = jQuery('#nav1btn'+pid).position();
		jQuery('#nav1btn'+pid).addClass('ph-aktiv2');
		jQuery(this).css({
			left: (p.left+1)+'px'
		});
		jQuery(this).attr("subnavvisible", "1");
		jQuery(this).attr("subnavpid", pid);
		jQuery(this).fadeIn(300);
	});
}

function ph_removeAllOtherSubnavs(pid) {
	jQuery('.ph-subnav').each(function(i,v) {
		if (jQuery(this).is('#subnav'+pid))
			return;
		var to = parseInt(jQuery(this).attr("subnavto"));
		if (to>0) {
			clearTimeout(to);
			jQuery(this).attr("subnavto", "-1");
		}
		if (jQuery(this).attr("subnavvisible")=="1") {
			jQuery('#nav1btn'+jQuery(this).attr("subnavpid")).removeClass('ph-aktiv2');
			jQuery(this).attr("subnavto", "-1");
			jQuery(this).attr("subnavvisible", "0");
			jQuery(this).stop().hide().css("opacity", 1);
		}
	});
}

function ph_hideSubnav(pid) {
	jQuery('#subnav'+pid).each(function(i,v) {
		jQuery(this).attr("subnavto", setTimeout("ph_hideSubnav2("+pid+");", 500));
	});
}

function ph_hideSubnav2(pid) {
	jQuery('#subnav'+pid).each(function(i,v) {
		jQuery('#nav1btn'+pid).removeClass('ph-aktiv2');
		jQuery(this).attr("subnavto", "-1");
		jQuery(this).attr("subnavvisible", "0");
		jQuery(this).fadeOut(150);
	});

}

function showNPO(npo_id, lang) {
	jQuery.get("./ajax/ajax.html", {npo_info: npo_id, lang: lang}, function(data) {
		jQuery("#txtHint").html(data);
	});
}

function getSubCategoryList(npocat_id, shop_id, lang, npo_id) {
	jQuery.get("./ajax/ajax.html", {npo_options: npocat_id, shop_id: shop_id, lang: lang, npo_id: npo_id}, function(data) {
		jQuery("#npo_id").html(data);
	});
}

function getSubCategoryListProfil(npocat_id, lang) {
	jQuery.get("./ajax/ajax.html", {npo_options_profil: npocat_id, lang: lang}, function(data) {
		jQuery("#npo_id").html(data);
	});
}

function ph_tipTip() {
	jQuery(function($) {
		var offset = -5;

		if ($.browser.msie) {
			offset = -12;
		}

		$(".tiptip").qtip({
			position: {
				my: "bottom center",
				at: "top center",
				adjust: {
					y: offset
				}
			},
			style: {
				classes: "ui-tooltip-dark ui-tooltip-tipsy"
			}
		});
	});
}

function ph_shopHinweis(buttonText) {
	jQuery(function($) {
		$(".ph-shophinweis").colorbox({
			initialWidth: 20,
			initialHeight: 20,
			width: 520,
			opacity: .7,
			inline: true,
			returnFocus: false,
			fixed: true,
			href: function() {
				return "#ph-prov-remark-" + $(this).attr("rel");
			}
		});
	});
}

function ph_brokenLink() {
	jQuery(function($) {
		$(".ph-brokenlink").colorbox({
			initialWidth: 20,
			initialHeight: 20,
			width: 520,
			height: 185,
			opacity: .7,
			close: '',
			returnFocus: false,
			fixed: true
		});
	});
}


