var selected;
var submitter = null;
 
function submitFunction() {
    submitter = 1;
}
function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}  

function popupImageWindow(url) {
  window.open(url,'popupImageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}	

/*** Flash player ***/	
function getFlashMovie(movieName) {  
	var isIE = navigator.appName.indexOf("Microsoft") != -1;   return (isIE) ? window[movieName] : document[movieName];  
}  

function playItem(id) {
	getFlashMovie("player").playItem(id);
}  
function stopItem(id) {
	getFlashMovie("player").stopItem();
	$("#track_" + id).removeClass("stop").addClass("play").attr("href", "javascript: playItem(" + id + ");");
	$("#track_" + id).parent().parent().removeClass("active");
}   

function itemSelected(id) {
	//called from Flash to switch an icon when next/prev song is chosen.
	//window.alert("Load item: "+id)
} 	

function nowPlaying(id) {
	$(".stop").each(function() {
		$(this).removeClass("stop").addClass("play");
		var temp = $(this).attr("id").split("_");
		$(this).attr("href", "javascript: playItem(" + temp[1] + ");");
		$(this).parent().parent().removeClass("active");
	});
	
	$("#track_" + id).removeClass("play").addClass("stop").attr("href", "javascript: stopItem(" + id + ");");
	$("#track_" + id).parent().parent().addClass("active");
}	
/******/

$(document).ready(		
	function() {
		
		/*** Moving active 2 level category to the top ***/
		var html = $(".cat > .nav > .active").html();
		if (html) {
			$(".cat > .nav > .active").remove();
			$(".cat > .nav > .first").removeClass("first");
			$(".cat > .nav").prepend('<li class="first active">'+html+'</li>');
		}
		
		
		$("input:image, img")
			.mouseover(function() { 
				var src = $(this).attr("src");
				pos = src.indexOf( 'buttons/' );
			    if (pos != -1) {
			    	var src = $(this).attr("src").match(/[^\.]+/) + "-over.jpg";
		            $(this).attr("src", src);
			    }
			    return false;
			})
			.mouseout(function() {
				var src = $(this).attr("src");
				pos = src.indexOf( 'buttons/' );
			    if (pos != -1) {
					var src = $(this).attr("src").replace("-over", "");
		            $(this).attr("src", src);
			    }
			    return false;
			});
		
		$("#checkout_payment .radio").click(function() {
			$(".pymnt_desc").hide();
			$(this).parent().next(".pymnt_desc").show();
		});
		
		if (typeof product_id != 'undefined') { /*** Flash player ***/
			var flashvars = {
				playlistURL: '/playlist.php?pid=' + product_id
			};

			var params = {
				menu: "true",
				scale: "noScale",
				allowFullscreen: "true",
				allowScriptAccess: "always",
				bgcolor: "#FFFFFF"
			};
			var attributes = {
				id:"player"
			};
			swfobject.embedSWF("/cms/files/player.swf", "player", "565", "68", "10.0.0", "/cms/files/expressInstall.swf", flashvars, params, attributes);
		}/******/
		
		$(".but_nach_oben").click(function() {
			$('html, body').animate({scrollTop:0}, 'slow');
	        return false;
		});
		
		$(".gal_bx_btm").each(function(){
			if ($(this).find(".pagingPrev").hasClass("gal_pre_btn_off") && $(this).find(".pagingNext").hasClass("gal_nxt_btn_off")) {
				$(this).hide();
				$(this).parent(".gal_bx").removeClass("gal_bx").addClass("gal_bx_no_buts");
			}
		});
		
		$("#itemsPerPage").unbind("change").bind("change", function() {
			$(this).parent("form").submit();
		})
		
		$("#sortBy").unbind("change").bind("change", function() {
			$(this).parent("form").submit();
		})
		
		$(".artists_tbl tr").mouseenter(function() {
			$(this).addClass("white");
		});
		
		$(".artists_tbl tr").mouseleave(function() {
			$(this).removeClass("white");
		});
		
		/* highlights module */
		
		$(".thumbs_text").each(function(){
			var currentTallest = 0;
			$(this).children().each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
			
			if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
			$(this).children().css({'min-height': currentTallest});
		});
		
		$(".thumbs_imgs").each(function(){
			var currentTallest = 0;
			$(this).children().each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
			
			if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
			$(this).children().css({'min-height': currentTallest});
		});
		
		$(".item").mouseenter(function() {
			var page = $(this).attr("class").split("item_no_");
			var no = page[1].split(" ");
			$(this).parents(".thumbs_row").find(".item_no_" + no[0]).addClass("hover");
		});
		
		$(".item").mouseleave(function() {
			var page = $(this).attr("class").split("item_no_");
			var no = page[1].split(" ");
			$(this).parents(".thumbs_row").find(".item_no_" + no[0]).removeClass("hover");
		});
		
		
		/* top categories */
		
		$('#lft_clm .curr_cats').unbind("mouseenter").bind("mouseenter", function(e) {
			if ($("#lft_clm .curr_cats").is(".closed")) {
				$("#lft_clm .curr_cats > .curr_cats_cnt > ul").hide();
				$(this).removeClass("closed").addClass("opened");
				$("#lft_clm .curr_cats > .curr_cats_cnt > ul").show(400);
			}
		});
		
		$('#lft_clm #closeTopCat').unbind("click").bind("click", function(e) {
			$(this).parents(".curr_cats").removeClass("opened").addClass("closed");
			$("#lft_clm .curr_cats > .curr_cats_cnt > ul").hide();
		});
		
		
		$('#rgt_clm .curr_cats').unbind("mouseenter").bind("mouseenter", function(e) {
			if ($("#rgt_clm .curr_cats").is(".closed")) {
				$("#rgt_clm .curr_cats > .curr_cats_cnt > ul").hide();
				$(this).removeClass("closed").addClass("opened");
				$("#rgt_clm .curr_cats > .curr_cats_cnt > ul").show(400);
			}
		});
		
		$('#rgt_clm #closeTopCat').unbind("click").bind("click", function(e) {
			$(this).parents(".curr_cats").removeClass("opened").addClass("closed");
			$("#rgt_clm .curr_cats > .curr_cats_cnt > ul").hide();
		});
		
		$('#rgt_clm .dl_links > ul > li > a').unbind("mouseenter").bind("mouseenter", function(e) {
			$(this).parent().addClass("active");
		});
		
		$('#rgt_clm .dl_links > ul > li > a').unbind("mouseleave").bind("mouseleave", function(e) {
			$(this).parent().removeClass("active");
		});
		
		$('#fnBxClose').unbind("click").bind("click", function(e) {
		    parent.top.$('#fancybox-close').trigger('click'); 
		});
		
		
		/* language selector */
		$('.lang_droppy').unbind("mouseenter").bind("mouseenter", function(e) {
			$("#langSelector").show(400);
			$('.lang_droppy').addClass("lang_over");
		});
		
		$('.lang_droppy').unbind("mouseleave").bind("mouseleave", function(e) {
			$("#langSelector").stop(true, true).hide();
			$('.lang_droppy').removeClass("lang_over");
		});
		
		$('.bx.cart').unbind("mouseenter").bind("mouseenter", function(e) {
			$(this).removeClass("closed").addClass("open");
			$(this).children("#CartContent").show(400);
		});
		
		$('.bx.cart').unbind("mouseleave").bind("mouseleave", function(e) {
			$(this).children("#CartContent").stop(true, true).hide();
			$(this).removeClass("open").addClass("closed");
		});
		
		
		$('#searchInput').unbind("focus").bind("focus", function(e) {
			if ($(this).val() == defaultSearch) {
				$(this).val('');
			}
		});
		
		$('#searchInput').unbind("blur").bind("blur", function(e) {
			if ($(this).val() == '') {
				$(this).val(defaultSearch);
			}
		});
		
		$('#loginboxEmail').unbind("focus").bind("focus", function(e) {
			if ($(this).val() == defaultEmail) {
				$(this).val('');
			}
		});
		
		$('#loginboxEmail').unbind("blur").bind("blur", function(e) {
			if ($(this).val() == '') {
				$(this).val(defaultEmail);
			}
		});
		
		$('#loginboxPassword').unbind("focus").bind("focus", function(e) {
			if ($(this).val() == defaultPassword) {
				$(this).val('');
			}
		});
		
		$('#loginboxPassword').unbind("blur").bind("blur", function(e) {
			if ($(this).val() == '') {
				$(this).val(defaultPassword);
			}
		});
		
		$('#NL_subscribe').unbind("focus").bind("focus", function(e) {
			if ($(this).val() == defaultNLSignup) {
				$(this).val('');
			}
		});
		
		$('#NL_subscribe').unbind("blur").bind("blur", function(e) {
			if ($(this).val() == '') {
				$(this).val(defaultNLSignup);
			}
		});
		
		
		$(".fancybox").fancybox({
			'titleShow'		: false,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		
		$(".fancybox_iframe").fancybox({
			'width'				: 676,
			'height'			: 534,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		
		
		
		$('a[href^=http]').click(
			function (e) { 
				var zyxDomains = false;
				for (var i=0;i<domais.length;i++) {
					if (this.href.indexOf(domains[i])<0) {
						zyxDomains = true;
					}
				}
				
				if (zyxDomains) {
					pageTracker._trackPageview(this.href);
					window.open(this.href);
					return false;
				}
			}
		)
		$('a[href^=/cms/files]').click(
			function (e) { 
			 pageTracker._trackPageview(this.href);
			 window.open(this.href);
			 return false;
			}
		)
		
		
		$('#createReviewButton').click( function(e) {
			var parent = $(this).parent();
			$.get($(this).parent().attr("href"), function(data) {
				parent.hide();
				$("#createReview").html(data);
				ajax_in_ajax();
			});
			return false;
		});
		
		
		var cross_sell = 0;		// Counter for cs pages
		
		$('#crossSellPrev').click( function(e) {
			if ($(this).is('.gal_pre_btn_on')) {
				$('.item').addClass("hidden");
				cross_sell -= 1;
				$('#cs_item_' + (cross_sell * 4 + 0)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 1)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 2)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 3)).removeClass("hidden");
				if (cross_sell == 0) {
					$('#crossSellPrev').removeClass("gal_pre_btn_on").addClass("gal_pre_btn_off");
				}
				$('#crossSellNext').removeClass("gal_nxt_btn_off").addClass("gal_nxt_btn_on");
				$('.cs_paging').removeClass("active");
				$('#item_' + (cross_sell+1)).addClass("active");
			}
		});
		
		$('#crossSellNext').click( function(e) {
			var max = $('#totalCsProducts').val();
			if ($(this).is('.gal_nxt_btn_on')) {
				$('.item').addClass("hidden");
				cross_sell += 1;
				$('#cs_item_' + (cross_sell * 4 + 0)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 1)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 2)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 3)).removeClass("hidden");
				if (cross_sell == max - 1) {
					$('#crossSellNext').removeClass("gal_nxt_btn_on").addClass("gal_nxt_btn_off");
				}
				$('#crossSellPrev').removeClass("gal_pre_btn_off").addClass("gal_pre_btn_on");
				$('.cs_paging').removeClass("active");
				$('#item_' + (cross_sell+1)).addClass("active");
			}
		});
		
		$('.cs_paging').click( function(e) {
			var pageId = $(this).attr("id");
			var page = pageId.split("_");
			
			if (page[1] > 0) {
				cross_sell = page[1] - 1;
				$('.item').addClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 0)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 1)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 2)).removeClass("hidden");
				$('#cs_item_' + (cross_sell * 4 + 3)).removeClass("hidden");
				
				$('.cs_paging').removeClass("active");
				$('#'+pageId).addClass("active");
				
				if (cross_sell == 0) {
					$('#crossSellPrev').removeClass("gal_pre_btn_on").addClass("gal_pre_btn_off");
				} else {
					$('#crossSellPrev').removeClass("gal_pre_btn_off").addClass("gal_pre_btn_on");
				}
				
				if (cross_sell >= ($('#totalCsProducts').val() - 1)) {
					$('#crossSellNext').removeClass("gal_nxt_btn_on").addClass("gal_nxt_btn_off");
				} else {
					$('#crossSellNext').removeClass("gal_nxt_btn_off").addClass("gal_nxt_btn_on");
				}
			}
		});	
		
		/*** New paging script ***/
		
		$('.pagingNext').click( function(e) {
			var highlights = $(this).parent().parent();
			var max = parseInt(highlights.children('.totalPages').val());
			var current_page = parseInt(highlights.children('.currentPages').val());
			
			if (current_page + 1 <= max) {
				highlights.find('.item').addClass("hidden");
				current_page += 1;
				highlights.find('.items_in_page_' + current_page).removeClass("hidden");
				if (current_page == max) {
					$(this).removeClass("gal_nxt_btn_on").addClass("gal_nxt_btn_off");
				}
				$(this).siblings('.pagingPrev').removeClass("gal_pre_btn_off").addClass("gal_pre_btn_on");
				highlights.find('.paging').removeClass("active");
				highlights.find('.page_item_' + current_page).addClass("active");
				highlights.children('.currentPages').val(current_page);
			}
		});
		
		$('.pagingPrev').click( function(e) {
			var highlights = $(this).parent().parent();
			var max = parseInt(highlights.children('.totalPages').val());
			var current_page = parseInt(highlights.children('.currentPages').val());
			
			if (current_page > 1) {
				highlights.find('.item').addClass("hidden");
				current_page -= 1;
				highlights.find('.items_in_page_' + current_page).removeClass("hidden");
				if (current_page == 1) {
					$(this).removeClass("gal_pre_btn_on").addClass("gal_pre_btn_off");
				}
				$(this).siblings('.pagingNext').removeClass("gal_nxt_btn_off").addClass("gal_nxt_btn_on");
				highlights.find('.paging').removeClass("active");
				highlights.find('.page_item_' + current_page).addClass("active");
				highlights.children('.currentPages').val(current_page);
			}
		});
		
		$('.paging').click( function(e) {
			var highlights = $(this).parent().parent().parent();
			var max = parseInt(highlights.children('.totalPages').val());
			
			var temp = $(this).attr("class").split("page_item_");
			var gotopage = parseInt(temp[1].substring(0,1));
			
			highlights.find('.item').addClass("hidden");
			highlights.find('.items_in_page_' + gotopage).removeClass("hidden");
			
			if (gotopage == 1) {
				highlights.find('.pagingPrev').removeClass("gal_pre_btn_on").addClass("gal_pre_btn_off");
			} else {
				highlights.find('.pagingPrev').removeClass("gal_pre_btn_off").addClass("gal_pre_btn_on");
			}
			
			if (gotopage == max) {
				highlights.find('.pagingNext').removeClass("gal_nxt_btn_on").addClass("gal_nxt_btn_off");
			} else {
				highlights.find('.pagingNext').removeClass("gal_nxt_btn_off").addClass("gal_nxt_btn_on");
			}
			highlights.children('.currentPages').val(gotopage);
		});	
		
				
		
		$('#tab_tracklist_l').click( function(e) {
			$('#tab_tracklist').show();
			$('#tab_description').hide();
			$('#tab_rating').hide();
			$('#tab_video').hide();
			$('#tab_products').hide();
			$('#tab_tracklist_l').addClass("active");
			$('#tab_products_l').removeClass("active");
			$('#tab_description_l').removeClass("active");
			$('#tab_video_l').removeClass("active");
		});
		
		$('#tab_description_l, #readMoreDesc, #moreDetails').click( function(e) {
			$('#tab_tracklist').hide();
			$('#tab_description').show();
			$('#tab_rating').hide();
			$('#tab_video').hide();
			$('#tab_products').hide();
			$('#tab_tracklist_l').removeClass("active");
			$('#tab_description_l').addClass("active");
			$('#tab_products_l').removeClass("active");
			$('#tab_video_l').removeClass("active");
		});
		
		$('#tab_products_l').click( function(e) {
			if (!$(this).hasClass("disabled")) {
				$('#tab_tracklist').hide();
				$('#tab_description').hide();
				$('#tab_rating').hide();
				$('#tab_video').hide();
				$('#tab_products').show();
				$('#tab_tracklist_l').removeClass("active");
				$('#tab_description_l').removeClass("active");
				$('#tab_products_l').addClass("active");
				$('#tab_video_l').removeClass("active");
				ajax_in_ajax();
			}
		});
		
		$('#tab_video_l').click( function(e) {
			if (!$(this).hasClass("disabled")) {
			$('#tab_tracklist').hide();
			$('#tab_description').hide();
			$('#tab_rating').hide();
			$('#tab_video').show();
			$('#tab_products').hide();
			$('#tab_tracklist_l').removeClass("active");
			$('#tab_products_l').removeClass("active");
			$('#tab_description_l').removeClass("active");
			$('#tab_video_l').addClass("active");
			}
		});
		
		$('.enlargeImage').unbind("click").bind("click", function(e) {
			var new_img = $(this).children("img").attr("src");
			new_img = new_img.replace("thumbnail_images", "popup_images");
			$("#popupMainImage").attr("src", new_img);
		});
		
		$("#searchInput").autocomplete("ajax_search_suggestions.php", {
			width: 426,
			selectFirst: false
		});
		
		function ajax_in_ajax() { 

			$(".thumbs_text").each(function(){
				var currentTallest = 0;
				$(this).children().each(function(i){
					if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
				});
				
				if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
				$(this).children().css({'min-height': currentTallest});
			});
			
			$(".thumbs_imgs").each(function(){
				var currentTallest = 0;
				$(this).children().each(function(i){
					if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
				});
				
				if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
				$(this).children().css({'min-height': currentTallest});
			});
			
			
			$('#submitReview').unbind("click").bind("click", function(e) {
				var rating = $("#createRating").val();
				var title = $("#createReviewTitle").val();
				var review = $("#review").val();
				
				if (rating < 1 || rating > 5) {
					$("#noRating").removeClass("hidden");
					return false;
				} else {
					$("#noRating").addClass("hidden");
				}
				
				if (review.length < 40) {
					$("#reviewToShort").removeClass("hidden");
					return false;
				} else {
					$("#reviewToShort").addClass("hidden");
				}
				
				var url = $("#product_reviews_write").attr("action");
				$.post(url, $("#product_reviews_write").serialize(),
				   function(data){
						window.location = window.location.href;
					   /*if (data == "ok") {
						    $("#createReview").html('');
						    url = url.replace("ajax_product_reviews_write", "ajax_product_reviews_last_update");
						    $.getJSON(url, function(data) {
						    	var html = "<strong>"+data.lastReview.AUTHOR+"</strong><br>";
						    	html += "<strong>"+data.lastReview.DATE+"</strong><br>";
						    	html += "<strong>"+data.lastReview.STARTS+"</strong><br>";
						    	html += "<strong>"+data.lastReview.TEXT+"</strong><br>";
						    	$("#newReview").html(html);
						    	$("#newReview").css("display", "block");
					    	});
					   }*/
				   });
				return false;
			});
			
			$('#reviewCancel').unbind("click").bind("click", function(e) {
				$("#createReview").html('');
				$("#createReviewButton").parent().show();
				return false;
			});
			
			$('#createReviewRating a').unbind("click").bind("click", function(e) {
				var rating = $(this).attr("class");
				rating = rating.replace("star", "rate");
				$('#createReviewRating').removeClass("rate_1 rate_2 rate_3 rate_4 rate_5").addClass(rating);
				$('#createRating').val(rating.substr(5,1));
				rating = rating.substr(5,1);
				$('#createReviewHelp').addClass('selected').html($('#createReviewHelp'+rating).html());
			});
			
			$('#createReviewRating a').unbind("mouseover").bind("mouseover", function(e) {
				if (!$('#createReviewHelp').is('.selected')) {
					var rating = $(this).attr("class");
					rating = rating.replace("star", "rate");
					$('#createReviewRating').removeClass("rate_1 rate_2 rate_3 rate_4 rate_5").addClass(rating);
						rating = rating.substr(5,1);
					$('#createReviewHelp').html($('#createReviewHelp'+rating).html());
				}
			});
			
			$('#createReviewRating a').unbind("mouseout").bind("mouseout", function(e) {
				if (!$('#createReviewHelp').is('.selected')) {
					$('#createReviewHelp').html('');
				}
			});
		}
	}
);


////////// Select box script ////////////

$(document).ready(function(){
// first locate all of the select tags on the page and hide them
$("select.changeMe").css('display','none');
//now, for each select box, run this function
$("select.changeMe").each(function(){
	
	var curSel = $(this);
	// get the CSS width from the original select box
	var gddWidth = $(curSel).css('width');
	var gddWidthL = gddWidth.slice(0,-2);
	var gddWidth2 = gddWidthL - 28;
	var gddWidth3 = gddWidthL - 16;
	// build the new div structure
	var gddTop = '<div style="width:' + gddWidthL + 'px" class="selectME" tabindex="0"><div class="cornerstop"><div><div></div></div></div><div class="middle"><div><div><div>';
	//get the default selected option
	var whatSelected = $(curSel).children('option:selected').text();
	//write the default
	var gddFirst = '<div class="first"><span class="selectME gselected" style="width:'+ gddWidth2 +  'px;">'+ whatSelected +'</span><span id="arrowImg"></span><div class="clears"></div></div><ul class="selectME">';
	// create a new array of div options from the original's options
	var addItems = new Array();      
	$(curSel).children('option').each( function() {           
		var text = $(this).text();  
		var selVal = $(this).attr('value'); 
		var before =  '<li style="width:' + gddWidthL + 'px;"><a href="#" rel="' + selVal + '" tabindex="0"  style="width:' + gddWidth3 + 'px;">';
		var after = '</a></li>';           
		addItems.push(before + text + after);
	});
	//hide the default from the list of options 
	//var removeFirst = addItems.shift();
	// create the end of the div selectbox and close everything off
	var gddBottom ='</ul></div></div></div></div><div class="cornersbottom"><div><div></div></div></div></div>'
	//write everything after each selectbox
	var GDD = gddTop + gddFirst + addItems.join('') + gddBottom;
	$(curSel).after(GDD);
	//this var selects the div select box directly after each of the origials
	var nGDD = $(curSel).next('div.selectME');
	
	$(nGDD).find('li:first').addClass("first");
	
	$(nGDD).find('li:last').addClass('last');
	//handle the on click functions - push results back to old text box
	$(nGDD).click( function(e) {
		 var myTarA = $(e.target).attr('rel');
		 var myTarT = $(e.target).text();
		 var myTar = $(e.target);
		 //if closed, then open
		 if( $(nGDD).find('li').css('display') == 'none')
			{
					//this next line closes any other selectboxes that might be open
					$('div.selectME').find('li').css('display','none');
					$(nGDD).find('li').css('display','block');
					
					//if user clicks off of the div select box, then shut the whole thing down
					$(document.window || 'body').click( function(f) {
							var myTar2 = $(f.target);
							if (myTar2 !== nGDD) {$(nGDD).find('li').css('display','none');}
					});
							return false;
			}
			else
			{      
					if (myTarA == null){
						$(nGDD).find('li').css('display','none');
								return false;
							}
							else {
								//set the value of the old select box
								$(curSel).val(myTarA);
								//set the text of the new one
								 $(nGDD).find('span.gselected').text(myTarT);
								 $(nGDD).find('li').css('display','none');
								 if ($(this).parents("form").hasClass("reload")) {
									 $(this).parents("form").submit();
								 }
								 return false;
							}
			}
	//handle the tab index functions
	 }).focus( function(e) {        
	 	        

		 $(nGDD).find('li:first').addClass('currentDD');
		 $(nGDD).find('li:last').addClass('lastDD');
		 function checkKey(e){
			//on keypress handle functions
			function moveDown() {
				var current = $(nGDD).find('.currentDD:first');
				var next = $(nGDD).find('.currentDD').next();
				if ($(current).is('.lastDD')){
				return false;
				} else {
					$(next).addClass('currentDD');
					$(current).removeClass('currentDD');
				}
			}
			function moveUp() {
				var current = $(nGDD).find('.currentDD:first');
				var prev = $(nGDD).find('.currentDD').prev();
				if ($(current).is('.first')){
				return false;
				} else {
					$(prev).addClass('currentDD');
					$(current).removeClass('currentDD');
				}
			}
			var curText = $(nGDD).find('.currentDD:first').text();
			var curVal = $(nGDD).find('.currentDD:first a').attr('rel');
		   switch (e.keyCode) {
				case 40:
					$(curSel).val(curVal);
					$(nGDD).find('span.gselected').text(curText);
					moveDown();
					return false;
					break;
				case 38:
					$(curSel).val(curVal);
					$(nGDD).find('span.gselected').text(curText);
					moveUp();
					return false;
					break;
				case 13:
					$(nGDD).find('li').css('display','none');
					}     
		}
		$(document).keydown(checkKey);	
	}).blur( function() {
			$(document).unbind('keydown');
	});
});
});


