jQuery.preloadImages = function()
	{
	for(var i = 0; i<arguments.length; i++)
		{
		jQuery("<img>").attr("src", arguments[i]);
		};
	};




$(document).ready(function() {

	// Language selection drop-down list hover
	
	$('.headlink').hover(
		function()
			{
			if ($.browser.msie && $.browser.version.substr(0,1)<7)
				{
				$('ul', this).show();
				}else{
				$('ul', this).slideDown('fast');
				}
			},
		function()
			{
			if ($.browser.msie && $.browser.version.substr(0,1)<7)
				{
				$('ul', this).hide();
				}else{
				$('ul', this).slideUp('fast');
				}
			}
	);
	
	
	// Login form - show/hide
	
	$('#login_button').click(function(){
		if ($('#login_user').is(':hidden'))
			{
			$('#login_user').slideDown();
			$('.login_status_text').fadeIn();
			}else{
			$('#login_user').slideUp();
			$('.login_status_text').fadeOut();
			};
	});
	
	// Login form - submit on keypressed Enter
	
	 $('#login_user').bind('keypress', function(e)
		{
		if ( e.keyCode == 13 )
			{
			$("#submit_anchor").click();
			}
		});


	// Search types - clicks (3 boxes)
	
	$('.search2_box').hide();
	$('.search3_box').hide();
	$('.search_list1').addClass('current');
	

	$('.search_item1').click(function()
		{
		if (!$('.search2_box').is(':hidden')) $('.search2_box').hide();
		if (!$('.search3_box').is(':hidden')) $('.search3_box').hide();
		if ($('.search1_box').is(':hidden')) $('.search1_box').show();
		$('.search_list1').addClass('current');
		$('.search_list2').removeClass('current');
		$('.search_list3').removeClass('current');
		});
	
	$('.search_item2').click(function()
		{
		if (!$('.search1_box').is(':hidden')) $('.search1_box').hide();
		if (!$('.search3_box').is(':hidden')) $('.search3_box').hide();
		if ($('.search2_box').is(':hidden')) $('.search2_box').show();
		$('.hidden2').slideToggle();
		$('.search_list1').removeClass('current');
		$('.search_list2').addClass('current');
		$('.search_list3').removeClass('current');
		});
	
	$('.search_item3').click(function()
		{
		if (!$('.search1_box').is(':hidden')) $('.search1_box').hide();
		if (!$('.search2_box').is(':hidden')) $('.search2_box').hide();
		if ($('.search3_box').is(':hidden')) $('.search3_box').show();
		$('.search_list1').removeClass('current');
		$('.search_list2').removeClass('current');
		$('.search_list3').addClass('current');
		});
		
	
	// New on Yellow pages - hovers (3 boxes)
		
	$('.item2_show').hide();
	$('.item3_show').hide();
	$('.list1').addClass('current');
	

	$('.item1').mouseover(function()
		{
		if (!$('.item2_show').is(':hidden')) $('.item2_show').hide();
		if (!$('.item3_show').is(':hidden')) $('.item3_show').hide();
		if ($('.item1_show').is(':hidden')) $('.item1_show').show();
		$('.list1').addClass('current');
		$('.list2').removeClass('current');
		$('.list3').removeClass('current');
		});
	
	$('.item2').mouseover(function()
		{
		if (!$('.item1_show').is(':hidden')) $('.item1_show').hide();
		if (!$('.item3_show').is(':hidden')) $('.item3_show').hide();
		if ($('.item2_show').is(':hidden')) $('.item2_show').show();
		$('.hidden2').slideToggle();
		$('.list1').removeClass('current');
		$('.list2').addClass('current');
		$('.list3').removeClass('current');
		});
	
	$('.item3').mouseover(function()
		{
		if (!$('.item1_show').is(':hidden')) $('.item1_show').hide();
		if (!$('.item2_show').is(':hidden')) $('.item2_show').hide();
		if ($('.item3_show').is(':hidden')) $('.item3_show').show();
		$('.list1').removeClass('current');
		$('.list2').removeClass('current');
		$('.list3').addClass('current');
		});
		
		
	// TOOLTIPS hovers, main file is: tooltips/tooltips_archive.html
	
	$('#category_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #categories'  // show the content of DIV id="categories"...
		});
	
	$('#service_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #service'
		});
		
	$('#location_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #location'
		});
	
	$('#location2_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #location'
		});
	
	$('#country_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #country',
		positions: ['top']
		});
	
	$('#state_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #state',
		positions: ['top']
		});
	
	$('#zip_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #zip',
		positions: ['top']
		});
	
	$('#city_tooltip').bt({
		ajaxPath: 'themes/default/tooltips/tooltips_archive.html #city',
		positions: ['top']
		});
	
	
	// Top right Stripe - adjust it according to body width
	function adjustImageRight()
		{
		var currentWidth = $('body').width();
		if (currentWidth < 1298)
			{
			var imageRight = (currentWidth - 970) / 2 + 958;
			var cssImageRight = imageRight + 'px top';
			$('.over_20m_listings').css('background-position', cssImageRight);
			}else{
			var cssImageRight = 'right top';
			$('.over_20m_listings').css('background-position', cssImageRight);
			};
		};
		
	adjustImageRight();

	var resizeTimer = null;
	$(window).bind('resize', function()
		{
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(adjustImageRight, 100);
		});
	
	// ZIG ZAG MENU ITEMS
	$( ".zigzag_menu ul li:first" ).addClass("first_zig");
	$( ".zigzag_menu ul li:last" ).addClass("last_zig");
	$( ".zigzag_menu ul li a" ).each(function(intIndex)
		{
		indent = intIndex * -18;
		indentText = indent + "px";
		$(this).css({ 'left' : indentText});
		});
	
	// also, we may preload images for IE6
	$.preloadImages("images/zigzag_middle2.png", "images/zigzag_first2.png", "images/zigzag_last2.png");
	
	
	
	// Continent Selection Fade
	$('.new_search_container a span').fadeOut();
	
	$('.new_search_container a').hover
		(
		function()
			{
			$(this).children('span').fadeIn();
			},
		function()
			{
			$(this).children('span').fadeOut();
			}
		);
	
	// County Selection Effects
	/*
	$('.select_item_box a').hover
		(
		function()
			{
			$(this).animate({ paddingLeft: "3" }, 150);
			},
		function()
			{
			$(this).animate({ paddingLeft: "0" }, 200);
			}
		);
	*/
	
	// Rounded Corners on Map-Based search results pages
	$('.popular_items_heading').corner('5px');
	$('.browse_items_heading').corner('5px');
	$('.search_results_page h5').corner('5px');
	
	// Changing number of items in selection row
	function refreshFooter()
		{
		$('.footer_bg').hide();
		$('.footer_bg').show();
		};
	
	function correctLineClearing(number)
		{
		$('.select_item_list .select_item_box').removeClass('clear');
		$('.select_item_list').each(function(n)
			{
			$(this).children().each(function(i)
				{
				if ((((i+1) % number) == 1) && (i != 0))
					{
					$(this).addClass('clear');
					};
				});
			});

		};
		
	function addCurrent(itsClass)
		{
		$('.change_two').removeClass('current');
		$('.change_three').removeClass('current');
		$('.change_four').removeClass('current');
		$('.change_five').removeClass('current');
		$('a.' + itsClass).addClass('current');
		};
	
	$('.change_two').click(function()
		{
		$('.content').removeClass('three_in_row');
		$('.content').removeClass('four_in_row');
		$('.content').removeClass('five_in_row');
		$('.content').addClass('two_in_row');
		addCurrent('change_two');
		correctLineClearing(2);
		refreshFooter();
		return false;
		});
	$('.change_three').click(function()
		{
		$('.content').removeClass('two_in_row');
		$('.content').removeClass('four_in_row');
		$('.content').removeClass('five_in_row');
		$('.content').addClass('three_in_row');
		addCurrent('change_three');
		correctLineClearing(3);
		refreshFooter();
		return false;
		});
	$('.change_four').click(function()
		{
		$('.content').removeClass('two_in_row');
		$('.content').removeClass('three_in_row');
		$('.content').removeClass('five_in_row');
		$('.content').addClass('four_in_row');
		addCurrent('change_four');
		correctLineClearing(4);
		refreshFooter();
		return false;
		});
	$('.change_five').click(function()
		{
		$('.content').removeClass('two_in_row');
		$('.content').removeClass('three_in_row');
		$('.content').removeClass('four_in_row');
		$('.content').addClass('five_in_row');
		addCurrent('change_five');
		correctLineClearing(5);
		refreshFooter();
		return false;
		});
	
	// Default columns number
	if ($('.change_two').hasClass('current'))
		{
		$('.change_two').click();
		} else 
			{
			if ($('.change_three').hasClass('current'))
				{
				$('.change_three').click();
				} else
					{
					if ($('.change_four').hasClass('current'))
						{
						$('.change_four').click();
						} else
							{
							$('.change_five').click();
							};
					};
			};
	
	// Scroll down to letter
	/*
	$('.first_letters ul li a').click(function(event)
		{
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 1000);
		});
	*/
	
});










$().ready(function() {
	
	/*
	$("#input1").autocomplete(["aleksinac", "aleksandrija", "amerika", "blic", "blace", "beocin"], {
		width: 320,
		max: 4,
		highlight: false,
		multiple: false,
		multipleSeparator: " ",
		scroll: true,
		scrollHeight: 300
	});
	*/
	
	$("#input1").autocomplete("index.php?section=companies&subsection=ajx_load_companies", {
		width: 260,
		selectFirst: false
	});
	/*
	$("#input2").autocomplete("index.php?section=companies&subsection=ajx_load_countries", {
		width: 260,
		selectFirst: false
	});
	*/
	$("#input2").autocomplete("index.php?section=companies&subsection=ajx_load_locations&load_country=true", {
		width: 260,
		selectFirst: false
	});
	
	$("#input3").autocomplete("index.php?section=companies&subsection=ajx_load_countries", {
		width: 260,
		selectFirst: false
	});
	
	$("#input4").autocomplete("index.php?section=companies&subsection=ajx_load_states", {
		width: 260,
		selectFirst: false
	});
	
	$("#input5").autocomplete("index.php?section=companies&subsection=ajx_load_zip_codes", {
		width: 260,
		selectFirst: false
	});
	
	$("#city").autocomplete("index.php?section=companies&subsection=ajx_load_cities", {
		width: 260,
		selectFirst: false
	});
	
	$("#input6").autocomplete("index.php?section=companies&subsection=ajx_load_categories", {
		width: 260,
		selectFirst: false
	});
	
	$("#input7").autocomplete("index.php?section=companies&subsection=ajx_load_locations&load_country=true", {
		width: 260,
		selectFirst: false
	});
	
	
});