var ie = document.all && (navigator.userAgent.toLowerCase().indexOf("msie") != -1);
var ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);

// getPageScroll() by quirksmode.com
//===============================================
	function ___getPageScroll() {
		var xScroll, yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
			xScroll = self.pageXOffset;
		} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		} else if (document.body) { // all other Explorers
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;	
		}
		arrayPageScroll = new Array(xScroll,yScroll);
		return arrayPageScroll;
	};

// NAICS GLOBALS
//===============================================
	var searchField = null;
	var naicsCodes = null;
	var naicsList = null;

	function filterNaics() {
		var rExp = new RegExp(searchField.value, "i");
		naicsCodes.options.length = 0;
		res = new Array();
		for (var i in naics) {
			if (naics[i].match(rExp)) {
				naicsCodes.options[naicsCodes.options.length] = new Option(naics[i], i);
			}
		}
	}
	
	function addNaics() {
		for (i=naicsCodes.options.length-1; i>=0; i--) {
			if (naicsCodes.options[i].selected) {
				naicsList.options[naicsList.options.length] = new Option(naicsCodes.options[i].text, naicsCodes.options[i].value);
				naicsCodes.options[i] = null;
			}
		}
	}
	
	function removeNaics() {
		for (i=naicsList.options.length-1; i>=0; i--) {
			if (naicsList.options[i].selected) {
				naicsList.options[i] = null;
			}
		}
	}

// REGISTRATION
//===============================================
	function limitWords(elem) {
		var wordCount = Math.max(0, wordCount = elem.value.split(/[\s\.\?]+/).length-1);
		if (wordCount > maxWordCount) {
			var words = elem.value.split(/[\s\.\?]+/).splice(0, maxWordCount);
			elem.value = words.join(' ');
		}
		var left = Math.max(0, maxWordCount - wordCount);
		$('#word_left').html(left == 0 || left == 1 ? left + ' word left' : left + ' words left');
	}

	function checkSubscription() {
		if ( $("#is_newsletter_confirm").length && $("#is_newsletter_confirm").val() == "0" && !document.getElementById('is_newsletter').checked) {
			if ( confirm("Please consider subscribing to the AmCham mailing list to stay up-to-date with our latest news, events or member offers.\nClick 'OK' if you wish to subscribe to the newsletter.") ) {
				$("#is_newsletter").attr("checked", "checked")
				$("#is_newsletter").parent('label').addClass('checked');
			}
			$("#is_newsletter_confirm").val('1');
		}
		return true;
	}

	
// DOM READY
//===============================================
	$(function() {
	
	// CUSTOM SELECT
	//===============================================
		$("div.select select").each(function() {
			if ( ie6 && $(this).attr('id') == "dir_category" ) {
				return;
			}
			$(this).InitCustomSelect();
		})
		
		$("div.selectnavlist").each(function() {
			$(this).addClass('select_init').click(function(e) {
				if ( $(this).hasClass('select_open') ) {
					$(this).removeClass('select_open');
					$("body").unbind("click");
				} else {
					$(this).addClass('select_open');
					setTimeout(function(){$("body").click(function(){ $("div.select").removeClass("select_open"); $("body").unbind("click"); }); },100); 
				}
			});
		});
	
		
	// CUSTOM RADIO
	//===============================================
		$('div.radiolist_wrp label').addClass('radio_init').each(function() {
			if ( $(this).find('input').attr('checked') ) {
				$(this).addClass('checked');
			}
		}).click(function (e) {
			e.preventDefault();
			$(this).parent().find('label').removeClass('checked');
			$(this).addClass('checked');
			$(this).find('input').attr('checked', true);
		});
		
	
	// INPUT ONFOCUS/ONBLUR
	//===============================================
		$("input.valueset").each(function(){
			$(this).focus(function(){
				if ($(this).val() == this.defaultValue) {
					$(this).val('').removeClass('example');
					if ($(this).attr("type")=="password") { 
						$(this).parent().find("span."+$(this).attr("id")).hide();
					}
					
					//autocomplete
					if ( $(this).attr('id') == 'login_email' ) {
						$(this).parent().find("span.login_password").hide();
					}
				}
			});
			$(this).blur(function(){
				if ($(this).val() == '') {
					$(this).val(this.defaultValue).addClass('example');
					//$(this).parent().find("span."+$(this).attr("id")).show();
					
					//autocomplete
					if ( $(this).attr('id') == 'login_email' ) {
						$(this).parent().find( "input#login_password" ).val('');
						$(this).parent().find("span.login_password").show();
					}
				}
			});
			if ($(this).attr("type")=="password") { 
				var that = $(this);
				$(this).parent().find("span."+$(this).attr("id")).click(function(){ that.focus(); });	
			}	
		});

	// INFOCUS SCROLL
	//===============================================
		$("div.infocus").scrollable({
			items: "div.items",
			item: "div.item",
			next: ".nextitem",
			prev: ".previtem",
			size: 1,
			loop: true,
			clickable: false,
			onSeek: function() {
				setInfocusHeight(this.getItems().eq(this.getIndex()).find(".lead").outerHeight(true),300);
			}
		});
	
		var minHeight = 266;
		function setInfocusHeight(h,s) {
			if (h<=minHeight /* && $("div.infocus").height()!=minHeight */) { h = minHeight; }
			$("div.infocus").animate({ height: h+'px' }, s);
			$("div.infocus div.items").animate({ height: h+'px' }, s);	
			$("div.infocus div.items div.item").animate({ height: h+'px' }, s);
			$("div.slider").css({ zoom: 1 });
		}
		setInfocusHeight($("div.infocus div.items div.item").eq(0).find(".lead").outerHeight(true),0);
	
		
	// NEWS SCROLL
	//===============================================
		$("div.slider div.window").scrollable({
			items: "ul",
			item: "li",
			next: ".next",
			prev: ".prev",
			size: 2
		});
		
		$("div.slider div.window a.hoverframe").each(function(){
			$(this).hover(function(){
				var that = $(this).parent(), 
					ofs = $(this).parent().position().left+60+$(this).closest(".slider").find(".window ul").position().left;
					
				$(this).parent().addClass("hover");
				$(this).closest(".slider").find(".ohf_top").css({ top: '-4px', left: ofs+'px' });
				$(this).closest(".slider").find(".ohf_right").css({ top: '-4px', left: 289+ofs+'px' });
				$(this).closest(".slider").find(".ohf_btm").css({ top: '56px', left: ofs+'px' });
				$(this).closest(".slider").find(".ohf_left").css({ top: '-4px', left: ofs+'px' });
				$(this).closest(".slider").find(".outerhoverframe").show();
			},function(){
				$(this).parent().removeClass("hover");
				$(this).closest(".slider").find(".outerhoverframe").hide();	
			});
		});
		
		
	// INFOCUS MEDIA CONTROL
	//===============================================
		$("div.infocus div.item").each(function(){
			if ($(this).find("div.media_gallery").length!=0 && $(this).find("div.media_video").length!=0) {
				$(this).find("div.media div.control span").each(function(){
					$(this).click(function(){ 
						if (!$(this).hasClass("onscreen") && !$(this).hasClass("active")) {
							$(this).parent().find("span").removeClass("active");
							$(this).parent().find("span.onscreen").replaceWith("");
							$(this).closest(".media").find(".media_onscreen").removeClass("media_onscreen");
							$(this).closest(".media").find(".media_"+$(this).attr("class")).addClass("media_onscreen");
							$(this).addClass("active").after('<span class="onscreen"></span>');
						}
					});	
				});												
			}
		});
		
	// HISTORY MILESTONES
	//===============================================
		$("div.milestones div.showcase div.items").scrollable({
			items: "ul", item: "li", next: ".next", prev: ".prev", size: 1, clickable: false,
			onSeek: function(e,i) {
				$("div.milestones div.years ul li a").css({ fontWeight: 'normal' });
				$("div.milestones div.years ul."+((i%2) ? "even" : "odd")+" li a").eq(Math.floor(i/2)).css({ fontWeight: 'bold' });
			}
		});
		
		$("div.milestones div.years ul li a").click(function(){
			$("div.milestones div.showcase div.items").scrollable().seekTo(($(this).text()*1)-1989);		
		});
	
		

	// CALENDAR
	//===============================================
		$("div.eventsbox div.calendar div.head").hover(function(){ $(this).addClass("head_hover"); },function(){ $(this).removeClass("head_hover"); });
	

	// LOGO ROTATOR
	//===============================================
		swfobject.embedSWF("swf/logo_rotator.swf", "logo_rotator_flash", "162", "153", "10", "", {}, { quality: "high", scale: "noscale", wmode: "transparent", allowscriptaccess: "always", bgcolor: "#ffffff" });
	

	// VOTE SUBMIT
	//===============================================
		$('#vote-form').submit(function(e) {
			e.preventDefault();
			$('#vote input:checked').each(function() {
				var vote = $(this).val();
				$('#vote').load('amcham/poll', { vote: vote });
			});
			return false;
		});
	
		$('#vote-result').click(function() {
			$('#vote').load('amcham/poll');
			return false;
		});
	
	
	// ARTICLE TEXT SIZE
	//===============================================
		var txtSize = 1;
	
		$('li.plus a').click(function(e) {
			e.preventDefault();
			if ( txtSize > 2 ) {
				return false;
			}
			
			txtSize++;
			
			$("div.article")
				.removeClass('txts1')
				.removeClass('txts2')
				.removeClass('txts3')
				.addClass('txts' + txtSize);
	
		});
		
		$("li.minus a").click(function(e) {
			e.preventDefault();
			
			if ( txtSize < 2 ) {
				return false;
			}
			
			txtSize--;
			
			$("div.article")
				.removeClass('txts1')
				.removeClass('txts2')
				.removeClass('txts3')
				.addClass('txts' + txtSize);
		});
	
		
	// ARTICLE TABLE FUNCTION LINKS (force the <a> to fill the table cell)
	//===============================================
		$("table.table td.func a").each(function(){
			$(this).css({ height: $(this).parent().height()+'px', lineHeight: $(this).parent().height()+'px' });
		});
	

	// GALLERY POPUP AND SLIDER
	//===============================================
		// SWF Load
		initSWF = function( targetPopup, triggerA, actIdx ) {
			var targetId = $( targetPopup + ' div.imgbg div' ).eq(actIdx-1).find('span').attr('id');
			var videoFile = triggerA.parent().find('span').eq(0).html();
			//alert( videoFile );

			var flashvars = { type: 'video', media_url: videoFile };
			var flashparams = {};
			var flashattributes = {};
				
			swfobject.embedSWF("/swf/mediaplayer_big.swf", targetId, "546", "364", "9.0.0", flashparams, flashvars, flashattributes);
		}
		
		stepSlide = function( targetPopup, triggerA, actIdx ) {
			
			var $visibleSlide = $( targetPopup + ' div.imgbg div:visible' );
			var $nextSlide = $visibleSlide.parent().find("div").eq(actIdx-1);
			var videocontentId = false;
			
			// hide / fadeOut
			if ( $visibleSlide.find("object").length ) {
				videocontentId = $visibleSlide.find("object").attr("id");
				$visibleSlide.hide().html( '<span id="' + videocontentId + '"></span>' );
			} else {
				// ha a kovetkezo slide video, akkor nem kell az anim
				if ( $nextSlide.find("span").length ) {
					$visibleSlide.hide();
				} else {
					$visibleSlide.fadeOut();
				}
			}
		
			// show / fadeIn
			if ( $nextSlide.find("span").length ) {
				$nextSlide.show();
				$( targetPopup + ' h4' ).html( triggerA.parent().find('span').eq(1).html() );
				$( targetPopup + ' p' ).eq(1).html( triggerA.parent().find('span').eq(2).html() );
				$( targetPopup + ' div.uppercontrol span' ).eq(0).html( actIdx );
			} else {
				$nextSlide.fadeIn(function() {
					$( targetPopup + ' h4' ).html( triggerA.parent().find('span').eq(1).html() );
					$( targetPopup + ' p' ).eq(1).html( triggerA.parent().find('span').eq(2).html() );
					$( targetPopup + ' div.uppercontrol span' ).eq(0).html( actIdx );
				});
			}
		}

		//AJAX callback
		popupGalleryCallback = function( targetPopup, exposeApi ) {
			
			$(targetPopup).fadeIn();
			
			$(targetPopup).find('a.close').click(function(e) {
				e.preventDefault();
				$(targetPopup).find("object").hide();
				$(targetPopup).fadeOut('fast');
				exposeApi.close();
			});
			
			//also slider
			var galleryPopupSliderApi = $( targetPopup + ' div.window').scrollable({
				size: 7,
				clickable: false,
				api: true
			});
			
			//thumbnail kattintasra event
			var lastIdx = $( targetPopup + ' div.uppercontrol span' ).eq(1).html()*1;
			var actIdx = 1;
	
			$( targetPopup + ' div.window a').click(function(e) {
				e.preventDefault();
				
				var triggerA = $(this);
				
				if ( $( targetPopup + ' div.imgbg div' ).index( $( targetPopup + ' div.imgbg div:visible' ).get(0) ) == $( targetPopup + ' div.window a').index(this) ) {
					//ugyanazon a slideon vagyunk amire kattintottak
					return true;
				}
				
				actIdx = $( targetPopup + ' div.window a').index(this)+1;
				
				$(this).parent().parent().find('li')
					.removeClass('sel')
					.end().end()
					.addClass('sel');
				
				if ( $(this).parent().hasClass('video') ) {					
					//buzi IE nem kapcsolja le a flasht, ezert muszaj mindig inicializalni :(
					stepSlide( targetPopup, triggerA, actIdx );
					initSWF( targetPopup, triggerA, actIdx );
				} else {
					var img = new Image();
					img.onload = function() {
						stepSlide( targetPopup, triggerA, actIdx );
					}
					//Preload
					img.src = triggerA.parent().find('span').eq(0).html();
				}
			});
			
			//felso lapozo
			$( targetPopup + ' div.uppercontrol a.upper-prev' ).click(function(e) {
				e.preventDefault();
				if ( actIdx > 1 ) {
					actIdx--;
					galleryPopupSliderApi.prev();
					$( targetPopup + ' div.window a').eq(actIdx-1).click();
				}
			});
			
			$( targetPopup + ' div.uppercontrol a.upper-next' ).click(function(e) {
				e.preventDefault();
				if ( actIdx < lastIdx ) {
					actIdx++;
					galleryPopupSliderApi.next();
					$( targetPopup + ' div.window a').eq(actIdx-1).click();
				}
			});
			
			//Ha az elso elem video, akkor rogton inicializalnunk kell a playert.
			if ( $( targetPopup + ' div.window li').eq(0).hasClass('video') ) {
				setTimeout( function() { initSWF( targetPopup, $( targetPopup + ' div.window a').eq(0), 1 ) }, 400 );
			}
			
		}
	
		//init
		$("a.popupgallery").click(function(e) {
			e.preventDefault();
			var pureId = $(this).attr('href').split("_");
			var popupId = $(this).attr('href');
			
			//expose
			var exposeApi = $( "#popuploader" ).expose({
				api: true,
				color: "#011b31",
				opacity: "0.85",
				onBeforeLoad: function() {
					var pageXSroll = ___getPageScroll();
					this.getExposed()
						.css({top: pageXSroll[1] + 40 + 'px'});
				},
				onBeforeClose: function() {
					if ( $(popupId).length ) {
						$( popupId ).fadeOut('fast', function() {
							$("#popuploader").empty();
						});
					} else {
						$("#popuploader").empty();
					}
				}
			}).load();
			
			$("#popuploader").append('<div class="loading"><img src="i/ajax-loader.gif" alt="loading" /><br/> loading...</div>');
			$("#popuploader div").fadeIn("fast");
			$("#popuploader").load("/popup/gallery/id/" + pureId[1], "?nocache=" + 1*new Date(), function() { popupGalleryCallback( popupId, exposeApi ) });
		});
		
		$('#gallerytoshow').each(function() {
			$(this).trigger('click');
		});
		
	// MEMBERSHIP SUBMIT
	//===============================================
		$("#membersearch_form button").click(function(e) {
			e.preventDefault();
			if ( $("#membersearch_form input[type=text]").val() == "Example: AmCham Foundation" ) {
				$("#membersearch_form input[type=text]").val("");
			}
			$("#membersearch_form form").submit();
		});


	// CUSTOM CHECKBOX
	//===============================================
		$('label.bottomcheck, div.newsletter_big label, div.checkboxlist_wrp label, div.blocklabel label').each(function() {
			if ( $(this).find(':checkbox').attr('checked') ) {
				$(this).addClass('checked').addClass('checked');
			}
		}).click(function (e) {
			e.preventDefault();
			if ( $(e.target).attr('href')) {
				e.stopPropagation();
				window.open( "/" + $(e.target).attr('href'), '_blank');
				return;
			} else {
				if ( $(this).hasClass('checked') ) {
					$(this).removeClass('checked');
					$(this).find('input').attr('checked', false);
				} else {
					$(this).addClass('checked');
					$(this).find('input').attr('checked', true);
				}
			}
		});
		
		if ( ! ie6 ) {
			$('label.bottomcheck, div.newsletter_big label, div.checkboxlist_wrp label, div.blocklabel label').addClass('check_init');
		} else {
			$('div.newsletter_big label, div.checkboxlist_wrp label, div.blocklabel label').addClass('check_init');
		}
		

	// EMAIL ADDRESS
	//===============================================		
		$("a.replaceemail").each(function() {
			while ( $(this).attr('href').indexOf( ' [__pont__] ' ) != -1 ) {
				$(this).attr('href', $(this).attr('href').replace(/\ \[\_\_pont\_\_\]\ /, '.') );
			}
			$(this)
				.attr('href', $(this).attr('href').replace(/\ \_\_\[kukac\]\_\_\ /, '@'))
				.html( $(this).attr('href').replace(/mailto:/, '') );
		});
	
			
	// DATEPICKER
	//===============================================
		if ( $.datepicker ) {
			$("#inreg_date_start").datepicker({
				dateFormat: 'yy-mm-dd'
			});
		}

	// COMPANY SEARCH AJAX
	//===============================================
	
		var ajaxCompanySearch = {
		
			displayDropDown : function( $obj ) {
				if ( $obj.val().length > 0 ) {
					$obj.parent().parent().parent().addClass("bigsearch_open");
					setTimeout(function(){$("body").click(function(){  $("div.registration div.bigsearch").removeClass("bigsearch_open"); $("body").unbind("click"); }); },100); 
				}
			},
			
			hideDropDown : function( $obj ) {
				$obj.parent().parent().parent().removeClass("bigsearch_open");
				$("body").unbind("click");
			},
		
			loadResults : function( $obj ) {
				if ( $obj.val().length > 0 ) {
					
					// ===>>> Tartalom torlese, loading uzenet ===>>>
					$obj.parent().parent().next().html('<img src="i/ajax-loader-small.gif" alt="loading..." />');
					this.displayDropDown( $obj );
					
					// ===>>> AJAXOS behuzasa a tartalomnak ===>>>
					var dropDownlist = '';
					$.get( "user/company", "text=" + encodeURI($obj.val()), function( data, textStatus ) {
						if ( data && data != '' ) {
							dropDownlist = "<ul>";
							$.each( data, function( key, val ) {
								dropDownlist += '<li><a href="/user/registermember?company=' + encodeURI(val).replace(/&/, '%26') + '">' + val + '</a></li>';
							});
							dropDownlist += "</ul>";
							$obj.parent().parent().next().html( dropDownlist ); 
						} else {
							dropDownlist = "No results.";
							$obj.parent().parent().next().html( dropDownlist ); 
						}
					}, 'json' );
				}
				
				if ( $obj.val().length < 1 ) {
					this.hideDropDown( $obj );
				}
			}	
		}
		
		/*
		var listIdx = 0;
		$("div.registration div.bigsearch").keyup(function(e) {
			
			// D ARROW
			if ( e.keyCode == 40 ) {
				e.stopPropagation();
				$(this).find('li').removeClass('hover').eq( listIdx++ )
					.addClass('hover').find('a')
						.focus();
			}
			
			// U ARROW
			if ( e.keyCode == 38 && listIdx > 0) {
				e.stopPropagation();
				$(this).find('li').removeClass('hover').eq( --listIdx )
					.addClass('hover').find('a')
						.focus();
			} 
			
			if ( e.keyCode == 38 && listIdx == 0 ) {
				e.stopPropagation();
				listIdx = 0;
				$(this)
					.find('li')
						.removeClass('hover')
					.end()
					.find('input')
						.focus();
			}
			
		});*/
		
		var timeout = undefined;
		$("div.registration div.bigsearch input").keyup(function(e) {
			if ( $(this).val().length < 1 ) {
				return;
			}
			
			// ALT, TAB, ENTER, HOME, END, L ARROW, R ARROW, U ARROW, D ARROW
			if ( $.inArray( e.keyCode, [18, 9, 13, 36, 35, 37, 39, 38, 40] ) != -1 ) {
				return;
			}
			
			if ( e.keyCode == 27 ) {
				// ESC-re bezarjuk a dropdownt
				ajaxCompanySearch.hideDropDown( $(this) );
				return;
			}

			// ne inditsunk minden pillanatban a gepeles alatt AJAX kerest, idoeltolas a gepeles miatt..
			if ( timeout != undefined ) {
				clearTimeout( timeout );
			}
			timeout = setTimeout( function() { ajaxCompanySearch.loadResults( $("div.registration div.bigsearch input") ) }, 250 );
		});
		
		// ha a dobozunkon belul kattintunk, igy nem csukodik be, mert a click event nem jut el a bodyhoz.
		$("div.registration div.bigsearch").click(function(e) {
			if ( $(this).hasClass( "bigsearch_open" ) ) {
				e.stopPropagation();
			} else {
				ajaxCompanySearch.displayDropDown( $(this).find("input") );
			}
		}).find( "form" ).submit(function(e) {
			e.preventDefault();
		});
		
		
		
	
	
	// NAICS
	//===============================================
		searchField = $('#naics-search').get(0);
		naicsCodes = $('#naics-codes').get(0);
		naicsList = $('#naics').get(0);
		
		//$('#naics-search').keyup(function(e) {});
		
		$('#naics-selects a').eq(0).click(function(e) {
			e.preventDefault();
			addNaics();
		});
				
		$('#naics-selects a').eq(1).click(function(e) {
			e.preventDefault();
			removeNaics();
		});
		
		$('#reg-form, #dictionary-form').submit(function() {
			for (i=naicsList.options.length-1; i>=0; i--) {
				naicsList.options[i].selected = true;
			}
		});
	
	// REGISTRATION
	// ===============================================
		if ( $('#reg_activities').length ) {
			$("#reg_activities").keyup(function() { limitWords( this ) });
			limitWords( $('#reg_activities').get(0) );
		}
		/*
		if ( $("#is_newsletter_confirm").length && $("#is_newsletter_confirm").val() == 1 ) {
			alert( "Please consider subscribing to the AmCham mailing list to stay up-to-date with our latest news, events or member offers." );
		}
		*/
	
		
	// HELP BUBBLE
	//===============================================
	
		$("div.helpbubble").each(function() {
			$("body").append($(this));
		});
	
		$("input.linebubbletrigger").focus(function() {
			$("div.linebubble").css({ top: $(this).offset().top + 25, left: $(this).offset().left - 8 }).fadeIn();
		}).blur(function() {
			$("div.linebubble").hide();
		});
		$("input.faxbubbletrigger").focus(function() {
			$("div.faxbubble").css({ top: $(this).offset().top + 25, left: $(this).offset().left - 8 }).fadeIn();
		}).blur(function() {
			$("div.faxbubble").hide();
		});
		$("input.mobilebubbletrigger").focus(function() {
			$("div.mobilebubble").css({ top: $(this).offset().top + 25, left: $(this).offset().left - 8 }).fadeIn();
		}).blur(function() {
			$("div.mobilebubble").hide();
		});
		
		$("input.contactbubbletrigger").focus(function() {
			$("div.contactbubble").css({ top: $(this).offset().top + 25, left: $(this).offset().left - 8 }).fadeIn();
		}).blur(function() {
			$("div.contactbubble").hide();
		});
		$("input.passwordbubbletrigger").focus(function() {
			$("div.passwordbubble").css({ top: $(this).offset().top + 25, left: $(this).offset().left - 8 }).fadeIn();
		}).blur(function() {
			$("div.passwordbubble").hide();
		});
	
	
		
	// IE6 fix
	// ===============================================
		
		if ( ie6 ) {
			// custom select overflow
			$(".select .listwrp ul, .bigsearch .listwrp ul").each(function() {
				if ( $(this).height() > 250 ) {
					$(this).css({height: "250px"});
				}
			});
	
			// Disapearing checkbox & error label
			$( 'div.customform label.bottomcheck, div.customform span.error_label' ).addClass('freshit');
		}
	
		
	});



// CUSTOM SELECT
//======================================================
	$.fn.InitCustomSelect = function() {
		var selected = '';
		var listItems = '';
		
		var time = 0;
		
		$(this).find("option").each(function(i){
			if ($(this).attr("selected")) {
				selected = [$(this).html(), $(this).val()];
				if ( $(this).html() == '' ) {
					listItems += '<li class="empty"><a href="#" rel="' + $(this).val() + '">' + $(this).html() + '</a></li>';
				} else {
					listItems += '<li><a href="#" rel="' + $(this).val() + '">' + $(this).html() + '</a></li>';
				}
			} else {
				listItems += '<li><a href="#" rel="' + $(this).val() + '">' + $(this).html() + '</a></li>';
			}
		});
		$(this).after('<div class="wrp"><div class="arrow"><div class="background">' + selected[0] + '</div></div><div class="listwrp"><ul>' + listItems + '</ul></div></div>').hide();
		
		//if ( ! $(this).hasClass('navigation') ) {
			$(this).parent().find('a').click(function(e) {
				e.preventDefault();
				$(this).parent().parent().parent().parent()
					.find("div.background")
						.html( $(this).html() )
					.end()
					.parent().find('select').val( $(this).attr('rel') ).change();
			});
		//}
		
		$(this).parent().addClass('select_init').click(function(e) {
			if ( $(this).hasClass('select_open') ) {
				$(this).removeClass('select_open');
				$("body").unbind("click");
			} else {
				// ha valami nyitva van, akkor zarjuk
				$("body").click();
				$(this).addClass('select_open');
				setTimeout(function(){$("body").click(function(e){
					$("div.select").removeClass("select_open"); $("body").unbind("click"); 
				}); },100); 
			}
		});
	};






// CUSTOM RADIO
//======================================================
	$.fn.InitCustomRadio = function() {
		var that = $(this);
		$(this).find("label").each(function(){
			$(this).click(function(){
				$(this).parent().find('input').attr('checked', false);
				$(this).find('input').attr('checked', true);
				if (!$(this).hasClass("checked")) {
					that.find("label").removeClass("checked").find("input");
					$(this).addClass("checked");
				}
			});
		});
		// if (debug) { $(this).find("button[type=submit]").click(function(){ alert(that.find("input[type=radio]:checked").val()); }); }
	};


