/*
Class: dwIMageProtector
Author: David Walsh
Website: http://davidwalsh.name
Version: 1.0.0
Date: 08/09/2008
Built For: jQuery 1.2.6


jQuery.fn.protectImage = function(settings) {
	settings = jQuery.extend({
		image: 'blank.gif',
		zIndex: 10
	}, settings);
	return this.each(function() {
		var position = $(this).position();
		var height = $(this).height();
		var width = $(this).width();
		$('<img />').attr({
			width: width,
			height: height,
			src: settings.image
		}).css({
			border: '1px solid #f00',
			top: position.top,
			left: position.left,
			position: 'absolute',
			zIndex: settings.zIndex
		}).appendTo('body')
	});
};

// sample usage

$(window).bind('load', function() {
$('img.protect').protectImage();
});

*/
(function($){
	$.fn.cleanDubleSpace = function() {
		while ($(this).val().search('  ') != -1) {
			$(this).val($(this).val().replace('  ', ' '));
		}
		return this;
	}
	$.fn.protectImage = function() {
		return this.each(function() {
			var position = $(this).position();
			var height = $(this).height();
			var width = $(this).width();
			$('<img />').attr({
				width: width,
				height: height,
				src: '/images/null.gif'
			}).css({
				border: '1px solid #f00',
				top: position.top,
				left: position.left,
				position: 'absolute',
				zIndex: '20'
			}).appendTo('body')
		});
	}
	$.fn.disableTextSelect = function() {
		if ($.browser.mozilla) {
			return this.each(function() {
				$(this).css({'MozUserSelect' : 'none'});
			});
		} else if ($.browser.msie) {
			return this.each(function() {
				this.onselectstart = function() { return false; };
				this.ondragstart = function() { return false; };
				this.unselectable = "on";
			});
		} else {
			$(this).live('mousedown', function() {
				this.unselectable = "on";
				return false;
			});
		}
	}
	$.fn.enableTextSelect = function() {
		if ($.browser.mozilla) {
			return this.each(function() {
				$(this).css({'MozUserSelect' : ''});
			});
		} else if ($.browser.msie) {
			return this.each(function() {
				this.onselectstart = function() { }; 
				this.ondragstart = function() { };
				this.unselectable = "on"; 
			});
		} else {
			$(this).unbind('mousedown', function() {
				this.unselectable = "off"; 
				return false;
			});
		}
	}
})(jQuery);
$(function() {
	initUl('selscountry', 1);
	$('ul#selsstate .liFirst').show()
	initUl('selscat', 3);
	$('#search').bind('click', function(event) {
		if ($('#radio_idsale').attr('checked'))
			$('#easearch input[name=src_cat]').val($('#selscat .liFirst span').text());
		else
			$('#easearch input[name=src_cat]').val(12);
		var country;
		switch ($('#selscountry .liFirst span').text()) {  
			case "Italy":  
				country = "IT";
			break; 
			case "Monaco":  
				country = "MC";
			break; 
			case "France":  
				country = "FR";
			break; 
			case "Austria":  
				country = "AT";
			break; 
			case "Bulgaria":  
				country = "BG";
			break; 
			case "Spain":  
				country = "ES";
			break; 
			case "Switzerland":  
				country = "CH";
			break; 
			case "Finland":  
				country = "FI";
			break; 
			case "Germany":  
				country = "DE";
			break; 
			case "Israel":  
				country = "IL";
			break; 
			case "USA":  
				country = "US";
			break; 
			case "UnitedKingdom":  
				country = "UK";
			break; 
			case "Greece":  
				country = "GR";
			break; 
			case "Czech":  
				country = "CZ";
			break; 
			default:  
				country = "no";
		} 
		$('#easearch input[name=src_country]').val(country);
		if ($('#selsstate .liFirst span').text() == "no" || $('#selsstate .liFirst span').text() == "")
			$('#easearch input[name=src_state]').val("no");
		else {
			$('#selsstate .liFirst span').remove();
			$('#easearch input[name=src_state]').val($('#selsstate .liFirst').text());
		}
		$('#easearch input[name=minvalue]').val($('#minvalue').val());
		$('#easearch input[name=maxvalue]').val($('#maxvalue').val());
		$('#selscountry .liFirst').html($('#selscountry li:eq(1)').html());
		$('#selscat .liFirst').html($('#selscat li:eq(1)').html());
		$('#selsstate').empty().html('<li class="liFirst"><span></span>Выберите регион...</li>').addClass('disabled').children('.liFirst').show();
		$('#minvalue').val("");
		$('#maxvalue').val("");
		$('#sLine2').html("");
		subInitUl();
		$('#easearch').submit();
	});
//	$('body *').disableTextSelect(); 
	$('img').bind('contextmenu', function(){ return false; });
});

var regs = new Array();
regs[0] = [1,0,0,0,0,1,0,1,0,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1]; // Европа
regs[1] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Италия
regs[2] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Испания
regs[3] = [1,1,1,1,1,1,1,1,1,1,1]; // Монако
regs[4] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Болгария
regs[5] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Франция
regs[6] = [1,1,1,1,1,1,1,1,1,1]; // Австрия
regs[7] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];// Швейцария
regs[8] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Германия
regs[9] = [1,1,1,1,1,1,1,1]; // Израиль
regs[10] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Финляндия
regs[11] = [1,1,1,1,1,1,1,1,1,1,1,1,1]; // США
regs[12] = [1,1,1,1,1]; // Великобритания
regs[13] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Греция
regs[14] = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; // Чехия

function subInitUl() {
	$('#place ul').each(function(index) {
		$(this).css('z-index', '1').children('li').hide();
		$(this).children('.liFirst').show().css('border-bottom', 'none');
	});
}
function initUl(idName, x) {
	var c = "Европа";
	$('ul#' + idName).children('.liFirst').show().click(function(event) {
		if ($(this).parent().children('li:last').css('display') != 'none') {
			$(this).parent().css('z-index', '1').children('li').hide();
			$(this).show().css('border-bottom', 'none');
		} else {
			subInitUl();
			$(this).parent().css('z-index', '50').children('li').show();
			$(this).css('border-bottom', '1px solid #a4d6ce');
		}
	})
	$('ul#' + idName).children('li:eq(1)')
		.hover(	function(event) { $(this).addClass('selAct'); },
			function(event) {
				$(this).removeClass('selAct');
			})
		.click(function(event) {
			subInitUl();
			$(this).parent().children('.liFirst').html($(this).html());
			if (x == 1) {
				$('#selsstate').empty().html('<li class="liFirst"><span></span>Выберите регион...</li>').addClass('disabled').children('.liFirst').show();
				setSelect($(this).children('span').text());
			}
			if (x == 2) {
				if ($('#selscountry .liFirst span').text() == "Israel")
					c = "Азия";
				else if ($('#selscountry .liFirst span').text() == "USA")
					c = "Америка";
				$('#sLine2').html(c + " &#187; " + $('#selscountry .liFirst').html()).children('span').remove();
			}
	})
	$('ul#' + idName).children('li:gt(1)')
		.hover(	function(event) {
				$(this).addClass('selAct');
				if (x != 3)
					sendFromJS($(this).children('span').text()); },
			function(event) {
				$(this).removeClass('selAct');
				if (x != 3)
					sendFromJS("@" + $(this).children('span').text());
			})
		.click(function(event) {
			if (x == 1)
				setSelect($(this).children('span').text());
			if (x == 2) {
				if ($('#selscountry .liFirst span').text() == "Israel")
					c = "Азия";
				else if ($('#selscountry .liFirst span').text() == "USA")
					c = "Америка";
				$('#sLine2').html(c + " &#187; " + $('#selscountry .liFirst').html() + " &#187; " + $('.selAct').html()).children('span').remove();
			}
			subInitUl();
			$(this).parent().children('.liFirst').html($(this).html());
	});
}
function recieveFromFlash(regName, x) {
	var c = "Европа";
	if (regName == 0)
		$('.selAct').removeClass('selAct');
	if (x == 1) {
		$('#selscountry li span:contains(' + regName + ')').parent().addClass('selAct');
		$('#sLine1').html($('#selscountry li span:contains(' + regName + ')').parent().html()).children('span').remove();
		subInitUl();
	} else if (x == 2) {
		$('#selsstate li span:contains(' + regName + ')').parent().addClass('selAct');
		$('#sLine1').html($('#selsstate li span:contains(' + regName + ')').parent().html()).children('span').remove();
		subInitUl();
	} else if (x == -1) {
		$('#selscountry .liFirst').html($('#selscountry li span:contains(' + regName + ')').parent().html());
		setSelect(regName);
	} else if (x == -2) {
		if (regName == 0) {
			$('#selscountry .liFirst').html($('#selscountry li:eq(1)').html());
			$('#selsstate').empty().html('<li class="liFirst"><span></span>Выберите регион...</li>').addClass('disabled').children('.liFirst').show();
			$('#sLine2').html("");
			return;
		}
		$('#selsstate .liFirst').html($('#selsstate li span:contains(' + regName + ')').parent().html());
		if ($('#selscountry .liFirst span').text() == "Israel")
			c = "Азия";
		else if ($('#selscountry .liFirst span').text() == "USA")
			c = "Америка";
		$('#sLine2').html(c + " &#187; " + $('#selscountry .liFirst').html() + " &#187; " + $('#selsstate li span:contains(' + regName + ')').parent().html()).children('span').remove();
	}
}
function reg5(x, i) {
	return (regs[x][i]);
}
function setSelect(regName) {
	var c = "Европа";
	$('#sLine1').html("");
	sendFromJS2(regName);
	if (regName != "dmEurope") {
		if ($('.selAct span').text() == "Israel")
			c = "Азия";
		else if ($('.selAct span').text() == "USA")
			c = "Америка";
		$('#sLine2').html(c + " &#187; " + $('.selAct').html()).children('span').remove();
		var url = "../?country=" + regName;
		$('#selsstate').empty().load(url, function() {
			$(this).removeClass('disabled');
			initUl('selsstate', 2); });
	} else {
		$('#sLine2').html("");
	}
}
function sendFromJS(regName) {
	if (regName == "dmEurope" || regName == "") {
		$('#sLine1').html("");
	} else {
		$('#sLine1').html($('.selAct').html()).children('span').remove();
	}
	if (window.movieName || document.movieName) {
		var movie = ($.browser.msie ? window : document)[movieName];
		movie.sendFromJS(regName);
	}
}
function sendFromJS2(regName) {
	regName = regName.toLowerCase();
	if (window.movieName || document.movieName) {
		var movie = ($.browser.msie ? window : document)[movieName];
		movie.sendFromJS2(regName);
	}
}
function embedFlash(width, height, src, name, movie, imgSrc) {
	if (navigator.userAgent.match(/AppleWebKit/i) && navigator.userAgent.match(/Mobile/i)) {
		document.write('<img src="' + imgSrc + '" width="' + width +'" height="' + height + '" />');
	} else {
		if (AC_FL_RunContent == 0) {
			document.write('<img src="' + imgSrc + '" width="' + width +'" height="' + height + '" />');
			alert("This page requires AC_RunActiveContent.js.");
		} else {
			return(AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
				'width', width,
				'height', height,
				'src', src,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'flash',
				'bgcolor', '#ffffff',
				'name', name,
				'menu', 'true',
				'allowFullScreen', 'false',
				'allowScriptAccess','sameDomain',
				'movie', movie,
				'salign', ''
				)); //end AC code
		}
	}
}

