$(document).ready(function(){
	
/*	$(document).pngFix(); */
/*
		if ($("#ccon").size() > 0){
			var pwi = 116;
			var blwi = $("#ccon").width();
			var pcnt = Math.floor(blwi/(pwi + 20));
		}
*/
/*
		function spbg_cals_num(){

			var elem = $('div.spbg div[class^="cals"]');
			if (elem.size() > 0){

				return (elem.attr("class").substr(4));
			}
		}

		var cals_num = parseInt(spbg_cals_num(), 10);
*/
		$('.part1w').hover(
			function(){
				$(this).children().attr('src', '/i/partners/veka-hoverw.png');
			}, function(){
				$(this).children().attr('src', '/i/partners/vekaw.png');
			}	
		);
		$('.part2w').hover(
			function(){
				$(this).children().attr('src', '/i/partners/siegenia-hoverw.png');
			}, function(){
				$(this).children().attr('src', '/i/partners/siegeniaw.png');
			}	
		);
		$('.part3w').hover(
			function(){
				$(this).children().attr('src', '/i/partners/sikkens-hoverw.png');
			}, function(){
				$(this).children().attr('src', '/i/partners/sikkensw.png');
			}	
		);
		$('.part4w').hover(
			function(){
				$(this).children().attr('src', '/i/partners/gu-hoverw.png');
			}, function(){
				$(this).children().attr('src', '/i/partners/guw.png');
			}	
		);
		$('div.spbg a').hover(
			function(){

				//var sp_elem = $('div.spbg div[class^="cals"]');
				var elem = $(this).parent();
				num = elem.attr("class").substr(4);

				num = parseInt(num, 10);
				if (num){
				//if (elem.size() > 0){
					$('a.sfrm' + num, elem).show();
				}
			},
			function(){

				var elem = $(this).parent();
				num = elem.attr("class").substr(4);

				num = parseInt(num, 10);
				if (num){
					$('a.sfrm' + num, elem).hide();
				}
			}
		);

		$('.rmrm').live("click", function(){

			$('a[rel="example_group"]', $(this).parent()).trigger('click');
			return false;
		});

		$('.tdata2 .ww1 .frm a').hover(
			function(){
				var elem = $(this).parent();

				$("a.maplnk", elem).show();
			},
			function(){
				var elem = $(this).parent();

				$("a.maplnk", elem).hide();
		});

		$("#ankt").click(function(){
			//$("#anktbl").toggle("slow");
			$("#anktbl").toggle();
			return false;
		});

		$('h2.bgn').click(function(){
			$(this).next().toggle();
			return false;
		}).next().hide();
		$(".frst").css("display","block");

		$('h2.bge').click(function(){
			$(this).next().toggle();
			return false;
		}).next().hide();
		$(".frst").css("display","block");

		$('h2.bgn').click(function(){
			var elem = $(this).parents("ol.qu2:first");

			elem.next().toggle();
			return false;

		}).next().hide();
		$(".frst").css("display","block");

		$(".flppup a").click(function(){

			if (!$(this).hasClass("actitm")) return false;
			else{
				$(".flppup a").addClass("actitm");

				$(this).removeClass("actitm");
				/*$(this).css({
					border: "none",
					color: "#489b3b",
					cursor: "text"
				});*/

				var clbl = "cglist" + $(this).attr("id").substr(3);

				$(".flppupbl div").each(function(){
					if ($(this).attr("id")){
						$("#" + $(this).attr("id")).css("display","none");
					}
				});
				$("#" + clbl).css("display","block");

				return false;
			}
		});

		$(".sgal .cals5 a").mouseover(
			function(){
				var elem = $(this).parent().parent();

				/*$("#ddp").parent().css("visibility", "visible");
				$("#ddp").text($(this).attr("title"));*/

				$("#ddp", elem).css("visibility", "visible");
				$("#ddp em", elem).text($(this).attr("title"));
				return false;
			}
		);
		$(".sgal .cals5 a").mouseout(
			function(){
				var elem = $(this).parent().parent();

				$("#ddp", elem).css("visibility", "hidden");
				return false;
			}
		);

		$(".sgal .cals8 a").hover(
			function(){	
				$(this).children('.sfrm8').show();
				return false;
			}, function(){				
				$(this).children('.sfrm8').hide();
				return false;
			}
		);


/*
		$(".ovdiv").mouseover(function(){
			$(this).css({
				backgroundColor: "#f1f4e5"
				//background: "transparent url(/i/sp_bg.png) repeat 0 0"
				//cursor: "pointer"
			});
		});
*/
		$(".ovdiv").mouseout(function(){
			$(this).css({
				backgroundColor: "transparent"
				//cursor: "text"
			});
		});




/*

		$('h4.act').click(function(){

			if(!$(this).data('flag')){
				$('span', this).removeClass("dashed");
				$('span', this).addClass("dashed2");
				$(this).next().show();
				$(this).data('flag', 1)
			}else{
				$('span', this).removeClass("dashed2");
				$('span', this).addClass("dashed");
				$(this).next().hide();
				$(this).removeData('flag');
			}
			return false;
		});
*/
/*
		$(function(){
			$("#hbut a#d2").css("cursor", "text");
			$("#hbut a#d2").click(
				function(){
					return false;
				}
			);
		});
*/
		$("#hbut a").click(function(){

			if ($(this).css("cursor") == "text"){
				return false;
			}else{
				if ($(this).attr("id") == "d1"){
					$(this).css({
						"background-position": "0 0",
						"cursor": "text"
					});
					$("#hbut a#d2").css({
						"background-position": "100% 0",
						"cursor": "pointer"
					});
					$("#hwin img").attr("src", "/i/okna/w1.png");
				}
				if ($(this).attr("id") == "d2"){
					$(this).css({
						"background-position": "100% 100%",
						"cursor": "text"
					});
					$("#hbut a#d1").css({
						"background-position": "0 100%",
						"cursor": "pointer"
					});
					$("#hwin img").attr("src", "/i/okna/p1.png");
				}
				//return false;
			}
		});
		$('.faqGoto a').click(function(){
			var parent = $(this).parent().parent();
			if ($(this).hasClass('active'))
			{
				$('.faqGoto a').removeClass('active');	
				$(parent).children('.colo4').hide();
			}else{				
				$('.faqGoto a').removeClass('active');				
				$('.faqGoto .colo4').hide();
				$(this).addClass('active');
				$(parent).children('.colo4').show();
			}
			return false;
		});
		$('.tblStyle tbody tr').hover(function(){
			$(this).addClass('hover');
		}, function(){
			$(this).removeClass('hover');
		});

		$(".various1").fancybox({
			 'width' : 750,
			 'height' : 550,
			 'autoScale' : false,
			 'transitionIn' : 'none',
			 'transitionOut' : 'none',
			 'type' : 'iframe'
		 }); 
		/*$("#bottomNavPrint").click(function(){
			$(this).hide();
			scriptTxt = ('<html><body><script type="text/javascript" language="javascript">	<!--	function printpage() {	window.print(); 	}	pstr = "<div class="btnPrint"><input type="button" onclick="printpage();" value="Напечатать" /></div>";	document.write(pstr);	//-->	</script>');
			dopTxt = ('<h2>Фирменные салоны продаж &laquo;окна от природы&raquo;</h2><p><em>194358, Санкт-Петербург, пр. Просвещения, д.&nbsp;30</em></p><table border="0" width="100%"><tbody><tr><td><img alt="" src="/images/prosvet_map_thumb.jpg"></td><td><p><em>prosvet@oknalife.ru <br>тел. 325-29-05, 515-34-83</em></p><p><em>График работы: <br>пн-пт.: 10:00&ndash;20:00 <br>сб-вс.: 11:00&ndash;19:00<br>Схема прохода до магазина на Просвещения<br/>Из метро 100&nbsp;метров налево до&nbsp;пр.&nbsp;Просвещения по&nbsp;пр.&nbsp;Просвещения 200&nbsp;метров налево в&nbsp;сторону Выборгского&nbsp;шоссе. Яркая зеленая вывеска &laquo;Окна&nbsp;от&nbsp;Природы&raquo;</em></p></td></tr></tbody></table><p><em>195027, Санкт-Петербург, Шепетовская ул., д.&nbsp;1 (угол Среднеохтинского пр. и Шепетовской ул.)</em></p><table border="0" width="100%"><tbody><tr><td><img alt="" src="/images/shepetovskaya_map_thumb.jpg"></td><td><p><em>sale@oknalife.ru<br>тел. 325-07-37, 224-15-09</em></p><p><em>График работы:<br>пн-пт.: 10:00-20:00<br>сб-вс.: 11:00-19:00<br>Ст. М. Новочеркасская выход из&nbsp;метро на&nbsp;5&nbsp;лестницу трамвай <br>&#8470;7, &#8470;10, &#8470;23<br>Ст. М. Новочеркасская выход из&nbsp;метро на&nbsp;6&nbsp;лестницу маршрутка <br>&#8470;6, &#8470;83к, &#8470;90к, &#8470;156к, &#8470;163к, &#8470;174, &#8470;190, &#8470;254, &#8470;269<br>Ст. М. Новочеркасская выход из&nbsp;метро на&nbsp;6&nbsp;лестницу автобус<br>&#8470;53, &#8470;181, &#8470;174</em></p></td></tr></tbody></table><p><em>191180, Санкт-Петербург, наб. р. Фонтанки, д.&nbsp;88</em></p><table border="0" width="100%"><tbody><tr><td><img alt="" src="/images/fontanka_map310_thumb.jpg"></td><td><p><em>fontanka@oknalife.ru<br>тел. 702-43-53, 571-35-26</em></p><p><em>График работы: <br>пн-пт.: 10:00-20:00 <br>сб-вс.: 11:00-19:00<br>Схема прохода до магазина на Фонтанке<br>От станции метро Сенная площадь 200&nbsp;метров по&nbsp;улице Гороховой в&nbsp;направлении наб.&nbsp;р.&nbsp;Фонтанки.</em></p></td></tr></tbody></table></body></html>');
			bodyImg = $('.k3').html();
			printImg = $('body').append(bodyImg);
			newWin=window.open('','printWindow','Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=1,Resizable=0');
			newWin.document.open();
			newWin.document.write(scriptTxt);
			newWin.document.write(bodyImg);
			newWin.document.write(dopTxt);
			
			newWin.print();
			newWin.close(); 
			return false;
		});*/
});
function change_over(c){

	var colo = "";
	if (c == "w") colo = "#f1f4e5";
	else colo = "#4f3914";

	$(".ovdiv").mouseover(function(){
		$(this).css({
			backgroundColor: colo
		});
	});
}

// gallery
$(function (){
	if($('#gallery').length){
		gallerymain();
	}
	if($('#galleryinner').length){
		gallerysmall();
	}
});
// gallery
function reload(e) { 
	name = e.name;
	value = e.value;
	//alert(name+"\n"+value);
	if(name=='matt')
		$("div#htypeID").load("/calcdata.php", {name: name,value: value});
	 if(name=='htype')
		$("div#confID").load("/calcdata.php", {name: name,value: value});
	return false;
}
	
function saveconf(id){
	//$("#confVal").value
	var idLink = $("#confVal").attr("value", id);
	$("#confVal").attr("value", id);
	var tt = $("#confID a[href*='javascript:saveconf("+id+");']");
	$('#confID a').removeClass('active');
	$(tt).addClass('active');		
}
	
var flag = 0;

function next(){
	if (flag==0){
		get_right();
	}else{
		get_next();
	}
}

function get_right()
{
    var qid = $("#qid").val(),
        selected = $('.fixwi input.vars:radio:checked').val();
    $(".fixwi input.vars,#nextbutton").attr("disabled", true);
	$.ajax( {
	   type: "POST",
	   url: "/examen.php",
	   data: "do=get_right&selected="+selected+"&qid="+qid,
       success: function(id) {
           if ( $( "#d_"+id+" input:radio" ).is( ":checked" ) )
               $( "#correctVar" ).show();
           else
               $( "#incorrectVar" ).show();
		   flag = 1;
           setTimeout( function() {
                get_next();
           }, 1000 );
	   }
	 } );
}

function printNewWin()
{
    window.open( "/examenResult.php" );
}

/*function get_right(){
	stopped = true;
	var selected = "";
	$('input:checkbox:checked').each(function(i) {
		if ($(this).hasClass("vars")){
			selected+=$(this).val()+" ";
		}
	});
	var qid = $("#qid").val();
	$.ajax({
	   type: "POST",
	   url: "/examen.php",
	   data: "do=get_right&selected="+selected+"&qid="+qid,
	   success: function(id){
		   var h = $("#d_"+id).html();
		   $("#d_"+id).html("<span>V</span>"+h);
		   flag = 1;
		   $(".vars").attr("disabled", true);
	   }
	 });
}*/

function get_next_without_showright(){
	//stopped = true;
	var selected = "";
	$('input:radio:checked').each(function(i) {
		if ($(this).hasClass("vars")){
			selected+=$(this).val()+" ";
		}
	});
	var qid = $("#qid").val();
	$.ajax({
	   type: "POST",
	   url: "/examen.php",
	   data: "do=get_next&selected="+selected+"&qid="+qid,
	   success: function(msg){
		   $("#container").html(msg);
		   flag = 0;
	   }
	 });
}

function get_next(){
	var qid = $("#qid").val();
	$.ajax({
	   type: "POST",
	   url: "/examen.php",
	   data: "do=get_next&qid="+qid,
	   success: function(msg){
		   $("#container").html(msg);
		   flag = 0;
	   }
	 });
}

function updateClock ( )
{
  var currentTime = new Date ( );

  var currentHours = currentTime.getHours ( );
  var currentMinutes = currentTime.getMinutes ( );
  var currentSeconds = currentTime.getSeconds ( );

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  var timeOfDay = '';

  // Convert the hours component to 12-hour format if needed
  currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;

  // Update the time display
  if ( document.getElementById("clock") )
      document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}

var milisec=0;
var stopped = false;

function display(){ 
 if (stopped){
	return false;
 }
 if (milisec<=0){ 
    milisec=9;
    time_limit-=1;
 } 
 if (time_limit==0){ 
    milisec=0;
	get_right();
	alert('Время вышло!');
 }else{
	milisec-=1;
    setTimeout("display()",100);
 }
}
$(function(){
$.fn.contImgBrd = function(){	
	$('img', $(this)).each(function(){	
		var align = this.align;		
		this.align = '';		
		var style = $(this).attr('style');		
		if( /left/.test(style)) {		
			var align = 'left';			
		} else if( /right/.test(style)) {		
			var align = 'right';		
		} else {
			var align = 'plain';			
		}		
		$(this).attr('style', '');	
		//$(this).wrap ');
		var img = $(this).attr('src');
		$(this).replaceWith('<div class="frm pos4 ind11"><img src="'+img+'" alt="" /></div>');
	});	
}
$('.icoa').contImgBrd();

$('#print a').click(function(){
		productDesc = $('#print img').attr('src');
		bodyImg = ('<img src="'+productDesc+'">');
		newWin=window.open('','printWindow','Toolbar=0,Location=0,Directories=0,Status=0,Menubar=0,Scrollbars=0,Resizable=0');
		newWin.document.open();
		newWin.document.write(bodyImg);
		newWin.print();
		newWin.close(); 
	    return false;
	});

$("#ssh").click( function() {
    var div = $(this).closest("form").children("div.spbg:eq(0)").toggleClass("hdn");
    if ( div.is( ":hidden" ) )
        $(this).text(($(this).is(".fact")?"изменить параметры поиска":"развернуть форму поиска"));
    else
        $(this).text("скрыть форму поиска");
} );
$("#sshf").closest('div').click( function() {
    var div = $("div.spbg:eq(0)").toggleClass("hdn");
    if ( div.is( ":hidden" ) )
        $("#sshf")/*$(this)*/.text("показать форму отзывов");
    else
        $("#sshf")/*$(this)*/.text("убрать форму отзывов");
} );

})

