﻿$(function () {
	bShadowBox = Shadowbox.init();
	$('div.ddheader').hover(function() {
		$(this).next('div.ddcontent').show();
	}, function() {
		$(this).next('div.ddcontent').hide();
	});
	$('div.ddcontent').hover(function() {
		$(this).show();
	}, function() {
		$(this).hide();
	});
})

function recount(){

var doc = document.getElementById('opt_price')

doc.innerHTML = 'новая стоимость'

};


var jCharacteristics;
var jOptPriceContainer;
var iBasePrice;

$(document).ready(function(){
	if ($.browser.opera) {
		$.support.opacity = true;
	}


	jCharacteristics = $('#characteristics');
	jOptPriceContainer = $('#opt_price').closest('div.opt_price');
//	var sPr = $('#base_price').text().replace(/[^\d]/g, '');
//	for (var i=0; i<sPr.length;i++) {alert(sPr + ' ' + i + ' ' + sPr.charCodeAt(i))};
	iBasePrice = parseInt($('#base_price').text().replace(/[^\d]/g, ''));
	
	$(':checkbox.cbox', jCharacteristics)
		.click(function () {
			if($.browser.msie){
				$(this).change();
			}
		})
		.change(function(){
			if ($(':checkbox:checked', jCharacteristics).length == 0) {
				jOptPriceContainer.fadeOut('slow');
			} else {
				jOptPriceContainer.fadeIn('slow');
			}
			
			var sum = iBasePrice;
			$(':checkbox:checked', jCharacteristics)
				.each(function () {
					sum += parseInt(this.value);
				});
				
			
			
//		replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
			$('#opt_price').html(sum.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1&nbsp;'));
			return false;
		}); 
});





   

$(function () {
	$('a.pw_close', '#popup_window_container').click(hide_popup_window);
	
$('a.ajaxform').click(function () {
		if ($('#popup_window').attr('currentPWC') != 'ajaxfeedback') {
			var path = $(this).attr("href");
			$.post('/feedback/ajax.html', '', function (data) {
 
$('#popup_window').html(path).attr('currentPWC', 'ajaxfeedback');
	
show_popup_window();
			});
		} else {
			show_popup_window();
		}
	
return false;
	});
})

function show_popup_window () {
	
	var arrPageSizes = ___getPageSize();
	$('embed, object, select').css({ 'visibility' : 'hidden' });	
	$('#overlay').css({
		backgroundColor:	'#000',
		opacity:			0.5,
		width:				arrPageSizes[0],
		height:				arrPageSizes[1]
	}).fadeIn();
	
	bShowPopup = true;
	$('#popup_window_container').show();
	$('#mask_content').show();
	$('#mask_content').animate({'opacity': 0.5}, 0);
	
	return false;
}
function hide_popup_window () {
	bShowPopup = false;
	$('#popup_window_container').hide();
	$('#mask_content').hide();
	$('#mask_content').animate({'opacity': 0}, 0);
	$('#overlay').hide();	
	$('embed, object, select').css({ 'visibility' : 'visible' });	
	return false;
}



		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};