var IE7_PNG_SUFFIX = "fix.png";
var i=0;

$(document).ready(function() {

	// img alt fix
		$('img').each(function(){
		if (!$(this).attr('alt')) { $(this).attr('alt',""); }
	});

	// skipnav
	/* 	$('a').click(function(){
			if (($(this).attr('href').substr(0,4) != "http") && ($(window).scrollTop() > ($('#menu').position().top) - 100) && ($(this).parent().parent().attr('id') != 'bar')) {
				var href = $(this).attr('href') + '#skipnav';
				$(this).attr('href',href);
			}
		}); */
	// png fix
	/* 	if ($.browser.msie) {
			$(this).find("img[src$='.png']").css('behavior','url(img/iepngfix.htc)');
		} */
		
	// SELECT
	$('div.select').each(function(){
		$(this).width($(this).find('span.select').width() + 26);
		$(this).find('ul.select').width($(this).find('span.select').width() + 26);
	});
	$('div.select').click(function(){

		$(this).css('z-index','1000');
		
		if ($(this).parent().find('ul.select').css('visibility') === 'hidden') {
		
			$(this).parent().find('ul.select').css('visibility','visible');
		} else
			$(this).parent().find('ul.select').css('visibility','hidden');

		return false;
	});

	$('ul.select li').click(function(){

		var val = (typeof $(this).attr('val') !== 'undefined') ? $(this).attr('val') : ''+$(this).text().trim();

		$(this).offsetParent().parent().find('input[type="hidden"]').val(val);
		$(this).offsetParent().parent().find('span.select').text($(this).text());
		$(this).parentsUntil('div.select').parent().attr('open','0').find('ul.select').css('visibility','hidden');

		// в заказе вызвать дополнительную функцию
		if ($(this).parent().attr('id') == 'orderService')
			order.changeService(this);
		
		// в голосовании снять проверку
		$(this).closest("div.poll-field").find('p').removeClass("error");
		
		return false;
	});
	$('div.select').hover(function(){},function(){

		$(this).attr('open','0').find('ul.select').css('visibility','hidden');
		$(this).css('z-index','600');
	});
	// /select

	// def-click
	$('.def-click').focus(function(){
		if ($(this).val() == $(this).attr('def')) {
			$(this).val('');
		}
	});
	$('.def-click').blur(function(){
		if ($(this).val() == '') {
			$(this).val($(this).attr('def'));
		}
	});

	// RADIO

	$('input.radio:checked').parent().addClass('radio-checked');
	$('label.checkradiobox').click(function(){

		if ($(this).children('span:first').children().attr('type') == 'radio' ) {

			var name = $(this).children('span:first').children().attr('name');
			
			$('input[name="'+name+'"]').removeAttr('checked').each(function(){
			
				if ($(this).parent().hasClass('radio')) {
					$(this).parent().removeClass('radio-checked');
				}
			});
			$(this).children('span:first').addClass('radio-checked').children().attr('checked','checked');
		}
	});

	// CHECKBOX
	
	$('input.checkbox[checked]').parent().addClass('checkbox-checked');

	if ($.browser.msie)
		$('span.checkbox').click(function(){
			if ($(this).hasClass('checkbox-checked')) {
				$(this).removeClass('checkbox-checked').children().removeAttr('checked');
			} else {
				$(this).addClass('checkbox-checked').children().attr('checked','checked');
			}
		});
	else
		$('input.checkbox').click(function(){
			if ($(this).parent().hasClass('checkbox-checked')) {
				$(this).removeAttr('checked').parent().removeClass('checkbox-checked');
			} else {
				$(this).attr('checked','checked').parent().addClass('checkbox-checked');
			}
		});
	/* $('.footer-menu a, #menu a').click(function(){
	return false;
	}); */

	// $('.plus').live('click',function(){

		// i++;		
		// var table = '<div class="filecontainer"><input type="file" class="fileins" name="file['+i+']"><span class="plus"><img src="_sys/img/plus.gif"></span><span class="minus"><img src="_sys/img/minus.gif"></span><br /><br /></div>';
				
		// $('#filearea').append(table);
	// });

	// $('.minus').live('click',function(){
		// $(this).parent().remove();
	// });

});

Array.prototype.in_array = function (what) {

    for (var i = 0; i < this.length; i++)
        if (what == this[i]) 
            return true;
			
    return false;
}

String.prototype.trim = function () {

	var	str = this;
		str = str.replace(/^\s\s*/, ''),
		ws = /\s/,
		i = str.length;
	while (ws.test(str.charAt(--i) ) );
	return str.slice(0, i + 1);
}

