$(function(){
	$(document).pngFix();
	
	if ($(window).width() > 1200) $('.col-main').addClass('wide');

	$('.icons li:first').css('border-left','0');
	$('.header #picto li:first').css('border-left','0');

	$('a.ico span').css('opacity','0');
	$('a.ico').parent().hover(function(){$(this).children('a.ico').children('span').stop().animate({opacity: '1'},300);},function(){$(this).children('a.ico').children('span').stop().animate({opacity: '0'},300)})

	$('#slogan div').hide(0);
	$('#slogan div:first').addClass('current').fadeIn();


	$('input.text').each(function(){
		var defvalue = $(this).attr('defvalue');
		if (defvalue) {
			 if ($(this).attr('value')=='') $(this).attr('value',defvalue);
			$(this).focus(function(){if ($(this).attr('value') == defvalue) $(this).attr('value','');})
			$(this).blur(function(){if ($(this).attr('value') == '') $(this).attr('value',defvalue);})
		} 
	})

	if ($.browser.msie) $('input.button').addClass('buttonie');
	$('input.button').focus(function(){
		$(this).addClass('focus');
	},function(){
		$(this).removeClass('focus');
	})

	$('.search-form .button-img').hover(function(){
		$(this).attr('src','/templates/default/images/button-search-hover.jpg')
	},function(){
		$(this).attr('src','/templates/default/images/button-search.jpg')
	})

	$('.connect-form .submit a').live('click',function(){
		if ($('#name').attr('value')==$('#name').attr('defvalue') || $('#email').attr('value')==$('#email').attr('defvalue')) {
			alert('Не все поля заполнены. Заполните их и попробуйте еще раз.');
			return false;
		} else {
			$('#connect-form').submit();
			return false;
		}
	});
	$('.icons .print').live('click',function(){
		window.print();
		return false;
	});

	$('.info .data h2 a').live('click',function(e){
		if ($(this).attr('name') && $('#container'+$(this).attr('name')).html()) e.preventDefault();
		if ($(this).hasClass('noaction')) exit;
		var tmp = $(this).attr('name');
		$('.accordeon').slideUp();
		if (tmp=="333_table") {
			$('#container333_table').load('/page-ast/table.php?' + new Date().getTime());
			if ($('#container'+tmp).css('display') == 'block') $('#container'+tmp).slideUp(300,function(){adjustCols(0);});
			else $('#container'+tmp).slideDown(300,function(){adjustCols(0);});
		} else {
			if ($('#container'+tmp).css('display') == 'block') $('#container'+tmp).slideUp(300,function(){adjustCols(0);});
			else $('#container'+tmp).slideDown(300,function(){adjustCols(0);});
		}
	});
	$('.accordeon').slideUp(0);

	
	
	if ($('#region_id').html() && $('#prodresults').html()) {
		$('#region_id').change(function(){
			$('#prodresults').text('');
		
			if ($(this).val()) $('#prodresults').load('/proceed_ws.php?rid='+$(this).val()+'&' + new Date().getTime(), function(){
				adjustCols(0);
			});
		
		});
	}
	
	$('.data a.lightbox').lightBox({
		txtOf: 'из',
		txtImage: 'Изображение'
	});


})

$(window).resize(function(){
	if ($(window).width() > 1200) $('.col-main').addClass('wide');
	else $('.col-main').removeClass('wide');
});
$(window).load(function(){
	adjustCols(0);
//	sloganRotator(5000);
//	regionCheck();
	partners();
})






function partners() {
	if ($('#regions').html()) {
	}
}


function regionCheck(){
	if ($('#regions').html()) {
		
			data = '';
			var dtype = (jQuery.browser.msie) ? 'text' : 'xml';
			$.ajaxSetup({async:false,cache:false}); 
			$.get("proxy.php", {"proxy_url": "http://ca.garant.ru/www/?list&xml"}, function(xhr){


       			var tmp;
        		if ( typeof xhr == 'string') {
            		tmp = new ActiveXObject( 'Microsoft.XMLDOM');
            		tmp.async = false;
            		tmp.loadXML(xhr);
        		} else {
	            	tmp = xhr;
        		}
				var _res = '';
				$(tmp).find("item").each(function(i){
					var name = $(this).find("name").text();
					var id = $(this).find("id").text();
					$("<option></option>").attr("value", id).text(name).appendTo("#regions"); 
//					$('#regions').append("<option value='"+id+"'>"+name+"<\/option>");
				});
//				alert($('#regions').html());
			}, dtype);


		$('#regions').change(function(){
			data = '';
			var dtype = (jQuery.browser.msie) ? 'text' : 'xml';
			$.ajaxSetup({async:false,cache:false}); 
			$.get("proxy.php", {"proxy_url": "http://ca.garant.ru/www/?price="+$(this).val()+"&xml"}, function(xhr){


       			var tmp;
        		if ( typeof xhr == 'string') {
            		tmp = new ActiveXObject( 'Microsoft.XMLDOM');
            		tmp.async = false;
            		tmp.loadXML(xhr);
        		} else {
	            	tmp = xhr;
        		}
				var _res = '';
				$('.results').text('');
				$(tmp).find("item").each(function(i){
					var name = $(this).find("name").text();
					var desc = $(this).find("description").text();
					var cost = $(this).find("cost").text();
					var txt  = "<p class='offeritem'><span class='cost'>"+cost+" р.</span><b>"+name+"</b><br />"+desc+'</p>';
					_res += txt;
				});
				$('.results').html(_res);
			}, dtype);
		})
	}
}




