if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
	try{ document.execCommand("BackgroundImageCache", false, true); } catch(e) {}
}

/*
 * .png{ filter: expression(fixPNG(this)); }
 */
function fixPNG(element, scale_mode) {
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;

		scale_mode = scale_mode || 'crop';

		if (element.tagName == 'IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "/f/1/global/i/0.gif";
			}
		} else {
			src = element.currentStyle.backgroundImage
					.match(/url\("(.+\.png)"\)/i)
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage = "none";
			}
		}

		var re_scale_mode = /iesizing\-(\w+)/;
		var m = re_scale_mode.exec(element.className);
		if (m) {
			scale_mode = m[1];
		}


		if (src)
			element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"
					+ src + "',sizingMethod='" + scale_mode + "')";
	}
}

var toggle = {

	/* SELECTORS */
	selector_master:".pseudo",
	selector_pseudo_visible:".pseudo_visible",
	selector_pseudo_hidden:".pseudo_hidden",
	selector_expand:".expand",
	selector_collapse:".collapse",
	selector_owner_master:".pseudo_to_much",

	class_master_selected:"show",
	/* * * * * * */

	init:function(selector_master){
		var that = this;

		$(this.selector_pseudo_hidden).hide();

		var selected = window.location.hash ? $(window.location.hash) : [];

		if(selected[0]) $(window).scrollTop(0);
		var is_first = true;

		$(selector_master || this.selector_master).click(function(){
			that.slave = that.getSlave(that.master = [this]);
			if(!is_first || !selected[0] || selected[0] === that.master[0] ) {
				//$(this).addClass("show");
				that.toggle();
			} else {
				$(this).removeClass("show")
			}
		}).click().filter(":has("+that.selector_expand+", "+that.selector_collapse+")").each(function(){
			that.appendMasterToSlaveMaster(this, that._is_expand(this));
		});
		is_first = false;
		$('#subnavigation').find(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden).data("not_first", true);
	},
	/* Берет slave
	 */
	getSlave:function(master){
		var slave = null;
		master = $(master || this.master);
		0 != (slave = $(master).next()).is(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden)
			|| 0 != (slave = $(master).next().find(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden)).length
				|| (0 != (slave = $(master).parent().next()).length
					|| (slave = $(master).parent().parent().next())
		);
		return slave;
	},
	/* Берет все блоки внутри slave
	 */
	getSlaveItems:function(slave){
		slave = $(slave || this.slave);
		return	$(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden, slave)
					.add(slave.is(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden) ? slave : []);
	},
	/* Добавляет связь псевдоссылок с псевдоссылкой
	 * более выского уровня
	 */
	appendMasterToSlaveMaster:function(master, slave){
		$(this.selector_master, slave).data("master", master);
	},
	getMasterItems:function(master){
		master = $(master || this.master);
		return $(master).find(this.selector_master);
	},
	/* Добавляет связь псевдоссылок с псевдоссылкой
	 * более выского уровня
	 */
	appendMasterToSlaveMaster:function(master, slave){
		$(this.selector_master, slave).data("master", master);
	},
	/*
	 * Анимация
	 */
	toggle:function(){
		var is_expand = null;
		if($(this.master).is(":has("+this.selector_expand+", "+this.selector_collapse+")")) {
			is_expand = $(this.selector_expand+":visible", this.master).length ? true : false;
			this.getSlaveItems(this.slave)[is_expand ? "show" : "hide"]();
			this._is_expand(this.master);
			this.setMasterStatus(this.getMasterItems(this.slave), is_expand);
		} else {
			var slave_items = this.getSlaveItems(this.slave);

			if(this.slave.parent().hasClass("fake")) {
				slave_items[this.slave.data('not_first') ? 'slideToggle' : 'toggle']();
				if(this.slave.data('not_first'))
					$(this.master).parents('#subnavigation:eq(0)').find(this.selector_pseudo_visible+", "+this.selector_pseudo_hidden).not(this.slave).slideUp();
				this.slave.data('not_first', true);
			} else {
				slave_items.toggle();
			}
			is_expand = slave_items.is(":visible") ? true : false;
			this._is_expand($(this.master).data("master"));
			this.setMasterStatus(this.master, is_expand);
		}
	},
	/* Узнаем, что должен показать pseudo master,
	 * expand или collapse
	 * */
	_is_expand:function(master){
		if(!master) return false;

		var slave = this.getSlave(master),
			slave_items = this.getSlaveItems(slave),
			is_expand = slave_items.filter(":hidden").length > slave_items.length / 2
				? true
				: false;

		this.setMasterStatus(master, is_expand);
		return slave;
	},
	/* Меняет текст в псевдоссылке
	 */
	setMasterStatus:function(master, is_expand){
		$(master)[is_expand ? "addClass" : "removeClass"](this.class_master_selected);
	}
};

function set_max_width(o, width, default_width){
	var width = (typeof width == 'array' || typeof width == 'object')
					? $(width).width()
					: parseInt(width);
	($.browser.msie && parseInt($.browser.version) < 7)
		? jCommon.measurer.bind(function(){
			$(o).width(default_width).width($(o).width() > width ? width : default_width);
		})
		: $(o).css({
			maxWidth: width+'px',
			width: default_width
		});
}

$(function(){
	toggle.init();

	$("div.picture div.wrapper")
		.before('<ins class="r t"><ins class="m3"><i></i></ins><ins class="m2"><i></i></ins><ins class="m1"><i></i></ins></ins>')
		.after('<ins class="r b"><ins class="m1"><i></i></ins><ins class="m2"><i></i></ins><ins class="m3"><i></i></ins></ins>')
		.each(function(){
			set_max_width($(this).parent(), $("img", this).attr("width"), '100%');
		});

	var shapes = {
		shape:[
			["M",[20,55]],
			["C",[22,41],[1,16],[25,3]],
			["C",[55,-9],[50,24],[66,33]],
			["C",[81,34],[92,6],[108,24]],
			["C",[119,45],[97,45],[98,56]],
			["C",[100,64],[115,63],[116,76]],
			["C",[116,83],[107,83],[104,87]],
			["C",[103,94],[102,100],[94,100]],
			["C",[78,95],[79,88],[63,92]],
			["C",[37,83],[30,104],[13,109]],
			["C",[-0,108],[-0,91],[1,88]],
			["C",[2,75],[18,65],[20,55]],
			["M",[-1,-1]],
			["L",[-1,-1]],
			["z"]
		],
		start:[
			{ index:0, data:["M",[34,57]] },
			{ index:1, data:["C",[37,42],[31,43],[37,38]] },
			{ index:2, data:["C",[47,30],[54,55],[68,43]] },
			{ index:3, data:["C",[81,33],[78,12],[95,19]] },
			{ index:4, data:["C",[114,28],[93,43],[94,54]] },
			{ index:5, data:["C",[93,62],[107,66],[102,73]] },
			{ index:6, data:["C",[99,78],[94,77],[90,82]] },
			{ index:7, data:["C",[86,88],[92,92],[85,95]] },
			{ index:8, data:["C",[76,98],[81,80],[61,82]] },
			{ index:9, data:["C",[46,83],[53,92],[39,97]] },
			{ index:10, data:["C",[21,102],[12,85],[20,76]] },
			{ index:11, data:["C",[29,66],[32,68],[34,57]] }

		],
		end:[
			{ index:0, data:["M",[20,55]] },
			{ index:1, data:["C",[22,41],[1,16],[25,3]] },
			{ index:2, data:["C",[55,-9],[50,24],[66,33]] },
			{ index:3, data:["C",[81,34],[92,6],[108,24]] },
			{ index:4, data:["C",[119,45],[97,45],[98,56]] },
			{ index:5, data:["C",[100,64],[115,63],[116,76]] },
			{ index:6, data:["C",[116,83],[107,83],[104,87]] },
			{ index:7, data:["C",[103,94],[102,100],[94,100]] },
			{ index:8, data:["C",[78,95],[79,88],[63,92]] },
			{ index:9, data:["C",[37,83],[30,104],[13,109]] },
			{ index:10,data:["C",[-0,108],[-0,91],[1,88]] },
			{ index:11,data:["C",[2,75],[18,65],[20,55]] }
		]
	};

	if($("#blot").length){
		var src = $("#blot img").attr("src");

		if(jCommon.support.vml) {
			shaper().createBlotVml("#blot", src.replace(/.png/, ".jpg"), shapes, true);
		} else if(jCommon.support.svg && !($.browser.safari && parseInt($.browser.version) < /*530*/531)) {
			//setTimeout(
			shaper().createBlotSvg("#blot", src.replace(/.png/, ".jpg"), shapes, true);
			//);
		}
	}

	$("div.picture:not(.not_round) img").each(function() {
		var isWide = $(this).parent().is('.wide_picture'),
			i_shape = new ictinus.Shape('m5.313,0 L0,5.313 L0,24.688 L5.313,30 L24.688,30 L30,24.688 L30,5.313 L24.688,0'),
			i = this,
			div = $(i).width() / $(i).height(),
			p = $(i).parent();

		var image = document.createElement('img');
		image.onload = function () {
			i.width = p.width();
			i.height = i.width / div;
			i_shape.setScaleGrid(15, 15, 15, 15);
			i_shape.strokeWidth = 1;
			i_shape.strokeColor = $("body").is(".dark") ? '#cccccc' : '#9e9e9e';
			i_shape.updateSizeBy(i);
			i_shape.decorate(i);
			if(isWide) {
				jCommon.measurer.bind(function(){
					i.width = p.width();
					i.height = i.width / div;
					i_shape.updateSizeBy(i);
					i_shape.decorate(i);
				});
			}
		};
		image.src = i.src;



	});
});

$.fx.step.teleportOut = function(fx) {
	//console.log(fx.pos);
	if(!fx.secondTime) {
		fx.elem = $(fx.elem).css('visibility', 'visible');
		fx.img = fx.elem.children('img').eq(0).css('visibility', 'visible');
		fx.copy = $('<div class="copy" style="width:'+fx.elem.width()+'px">'+fx.elem.html().replace(/style="[a-zA-Z0-9 ;:()=%-]+"/, '')+'</div>').appendTo(fx.elem);
		fx.noise =	$('<ins class="teleport_noise"></ins>').prependTo(fx.elem);
		fx.secondTime = true;
	}
	if(fx.pos < 0.5) fx.img.css('opacity', 1-(fx.pos*2));
	else fx.img.css('opacity', 0);

	if(fx.pos > 0.5) fx.copy.css('opacity', 1-((fx.pos-0.5)*2));


	if(fx.pos % 0.2 < 0.1) {
		fx.noise.css('top',-1*Math.random()*600+'px');
	}
	if(fx.pos % 0.5 > 0.1) {
		var delta = parseInt(Math.random()*30*fx.pos) - 15;
		fx.copy.css({left:delta, top:delta/4});
	}

	if(fx.pos % 0.4 < 0.3) {
		fx.noise.css('visibility', Math.random() > 0.5 ? 'visible' : 'hidden');
	}
	if(fx.pos == 1) {
		fx.copy.remove();
		fx.noise.remove();
		fx.img.css({opacity: 1, visibility:'hidden'});

	}
}

$.fx.step.teleportIn = function(fx) {
	//console.log(fx.pos);
	if(!fx.secondTime) {
		fx.elem = $(fx.elem);
		fx.img = fx.elem.children('img').eq(0).css({visibility:'visible', opacity:0});
		fx.copy = $('<div class="copy" style="width:'+fx.elem.width()+'px">'+fx.elem.html().replace(/style="[a-zA-Z0-9 ;:()=%-]+"/, '')+'</div>').appendTo(fx.elem).css({opacity:0});
		fx.noise =	$('<ins class="teleport_noise"></ins>').prependTo(fx.elem);
		fx.secondTime = true;
	}
	if(fx.pos < 0.9) fx.img.css('opacity', fx.pos*2);
	else fx.img.css('opacity', 1);


	var delta = parseInt(Math.random()*30*(1-fx.pos));
	fx.copy.css({left:delta, top:delta/4, opacity:fx.pos < 0.5 ? fx.pos : 1 - fx.pos});

	if(fx.pos % 0.2 < 0.1) {
		fx.noise.css('top',-1*Math.random()*600+'px');
	}

	if(fx.pos % 0.4 < 0.3) {
		fx.noise.css('visibility', Math.random() > 0.5 ? 'visible' : 'hidden');
	}
	if(fx.pos == 1) {
		fx.copy.remove();
		fx.noise.remove();
		fx.img.css({opacity: 1, visibility:'visible'});

	}
}

// Let's create a namespaced Calc object to handle all the tasks for this.
//
var Oversun = {
	// The calculator
	Calculator: {

		USD_COURCE: 30,
		TIME_MULTIPLIER: 10,

		data: {
			platforms: [
				{ id: 1, name: "Intel 1U SR1690WB", socket: "LGA1366", hdd_slots: 4, memory_type: "DDR3", memory_slots: 8, hot_swap: true, price: 1043 },
				{ id: 2, name: "Intel 1U SR1600URHS", socket: "LGA1366", hdd_slots: 3, memory_type: "DDR3", memory_slots: 12, hot_swap: true, price: 1038 },
				{ id: 3, name: "Intel 1U SR1630BC", socket: "LGA1366", hdd_slots: 2, memory_type: "DDR3", memory_slots: 8, hot_swap: false, price: 843 },
				{ id: 4, name: "Intel 2U SR2625URLX", socket: "LGA1366", hdd_slots: 8, memory_type: "DDR3", memory_slots: 12, hot_swap: true, price: 1619 },
				{ id: 5, name: "Intel 2U SR2600URBRPR", socket: "LGA1366", hdd_slots: 5, memory_type: "DDR3", memory_slots: 12, hot_swap: true, price: 1498 },
				{ id: 6, name: "Intel 1U SR1630HGP", socket: "LGA1156", hdd_slots: 3, memory_type: "DDR3", memory_slots: 6, hot_swap: true, price: 681 },
				{ id: 7, name: "Intel 1U SR1630GP", socket: "LGA1156", hdd_slots: 2, memory_type: "DDR3", memory_slots: 6, hot_swap: false, price: 617 },
				{ id: 8, name: "Intel 1U SR1530SH", socket: "LGA775", hdd_slots: 2, memory_type: "DDR2", memory_slots: 4, hot_swap: false, price: 605 },
				{ id: 9, name: "Intel 1U SR1530HSH", socket: "LGA775", hdd_slots: 3, memory_type: "DDR2", memory_slots: 4, hot_swap: true, price: 670 }
			],

			processors: [
				{ id: 1, name: "Intel Core 2 Quad Q9300", core: "Yorkfield ", socket: "LGA775", hhz: "2.50", cores_count: 4, mhz: 1333, cache: 6, price: 169 },
				{ id: 2, name: "Intel Core 2 Quad Q9400", core: "Yorkfield ", socket: "LGA775", hhz: "2.66", cores_count: 4, mhz: 1333, cache: 6, price: 190 },
				{ id: 3, name: "Intel Core 2 Quad Q9500", core: "Yorkfield ", socket: "LGA775", hhz: "2.83", cores_count: 4, mhz: 1333, cache: 6, price: 195 },
				{ id: 4, name: "Intel Core 2 Quad Q9550", core: "Yorkfield ", socket: "LGA775", hhz: "2.83", cores_count: 4, mhz: 1333, cache: 12, price: 266 },
				{ id: 5, name: "Intel Core 2 Quad Q9650", core: "Yorkfield ", socket: "LGA775", hhz: "3.00", cores_count: 4, mhz: 1333, cache: 12, price: 335 },
				{ id: 6, name: "Intel Xeon E5502", core: "Nehalem", socket: "LGA1366", hhz: "1.86", cores_count: 2, mhz: 4800, cache: 4, price: 224 },
				{ id: 7, name: "Intel Xeon E5503", core: "Nehalem", socket: "LGA1366", hhz: "2.00", cores_count: 2, mhz: 4800, cache: 4, price: 236 },
				{ id: 8, name: "Intel Xeon E5504", core: "Nehalem", socket: "LGA1366", hhz: "2.00", cores_count: 4, mhz: 4800, cache: 4, price: 271 },
				{ id: 9, name: "Intel Xeon E5506", core: "Nehalem", socket: "LGA1366", hhz: "2.13", cores_count: 4, mhz: 4800, cache: 4, price: 296 },
				{ id: 10, name: "Intel Xeon E5520", core: "Nehalem", socket: "LGA1366", hhz: "2.26", cores_count: 4, mhz: 5860, cache: 8, price: 456 },
				{ id: 11, name: "Intel Xeon E5530", core: "Nehalem", socket: "LGA1366", hhz: "2.40", cores_count: 4, mhz: 5860, cache: 8, price: 621 },
				{ id: 12, name: "Intel Xeon E5540", core: "Nehalem", socket: "LGA1366", hhz: "2.53", cores_count: 4, mhz: 5860, cache: 8, price: 826 },
				{ id: 13, name: "Intel Xeon E5550", core: "Nehalem", socket: "LGA1366", hhz: "2.66", cores_count: 4, mhz: 6400, cache: 8, price: 1148 },
				{ id: 14, name: "Intel Xeon E5560", core: "Nehalem", socket: "LGA1366", hhz: "2.80", cores_count: 4, mhz: 6400, cache: 8, price: 1329 },
				{ id: 15, name: "Intel Xeon E5560", core: "Nehalem", socket: "LGA1366", hhz: "2.93", cores_count: 4, mhz: 6400, cache: 8, price: 1590 },
				{ id: 16, name: "Intel Xeon E5630", core: "Westmere", socket: "LGA1366", hhz: "2.53", cores_count: 4, mhz: 5860, cache: 12, price: 703 }
			],

			memory: [
				{ id:1, name: "DDR-3 1Gb DIMM 1333 Mhz ECC", size: "1Gb", registered: true, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 52 },
				{ id:2, name: "DDR-3 2Gb DIMM 1333 Mhz ECC", size: "2Gb", registered: true, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 89 },
				{ id:3, name: "DDR-3 4Gb DIMM 1333 Mhz ECC", size: "4Gb", registered: true, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 169 },
				{ id:4, name: "DDR-3 8Gb DIMM 1333 Mhz ECC", size: "8Gb", registered: true, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 606 },
				{ id:5, name: "DDR-3 1Gb DIMM 1333 Mhz", size: "1Gb", registered: false, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 33 },
				{ id:6, name: "DDR-3 2Gb DIMM 1333 Mhz", size: "2Gb", registered: false, speed: "10600 Mb/s", mhz: 1333, memory_type: "DDR3", cl: 9, price: 62 },
				{ id:7, name: "DDR-2 1Gb DIMM 800 Mhz", size: "1Gb", registered: false, speed: "6400 Mb/s", mhz: 800, memory_type: "DDR2", cl: 5, price: 34 },
				{ id:8, name: "DDR-2 1Gb DIMM 800 Mhz", size: "2Gb", registered: false, speed: "6400 Mb/s", mhz: 800, memory_type: "DDR2", cl: 5, price: 59 }
			],
			hdds:[
				{ id:1, name: "250Gb SATA-II", size: "250 Gb", cache: "32Mb", rpm: 7200, formfactor: "3,5", hdd_type: "SATA-II", price: 70 },
				{ id:2, name: "500Gb SATA-II", size: "500 Gb", cache: "32Mb", rpm: 7200, formfactor: "3,5", hdd_type: "SATA-II", price: 93 },
				{ id:3, name: "750Gb SATA-II", size: "750 Gb", cache: "32Mb", rpm: 7200, formfactor: "3,5", hdd_type: "SATA-II", price: 150 },
				{ id:4, name: "1000Gb SATA-II", size: "1000 Gb", cache: "32Mb", rpm: 7200, formfactor: "3,5", hdd_type: "SATA-II", price: 160 },
				{ id:5, name: "146Gb SAS 10k", size: "146 Gb", cache: "16Mb", rpm: 10000, formfactor: "2,5", hdd_type: "SAS", price: 180 },
				{ id:6, name: "300Gb SAS 10k", size: "300 Gb", cache: "16Mb", rpm: 10000, formfactor: "2,5", hdd_type: "SAS", price: 298 },
				{ id:7, name: "146Gb SAS 15k", size: "146 Gb", cache: "16Mb", rpm: 15000, formfactor: "3,5", hdd_type: "SAS", price: 185 },
				{ id:8, name: "300Gb SAS 15k", size: "300 Gb", cache: "16Mb", rpm: 15000, formfactor: "3,5", hdd_type: "SAS", price: 329 },
				{ id:9, name: "450Gb SAS 15k", size: "450 Gb", cache: "16Mb", rpm: 15000, formfactor: "3,5", hdd_type: "SAS", price: 470 }
			]
		},

		helpers: {
			hdd: function( platformId ){
				var slots = Oversun.Calculator.data.platforms[platformId].hdd_slots;
				$("#hdd-wrap").html("");

				var typeSelect = $('<div><label for="hdd-type-select">Тип жестких дисков</label><select id="hdd-type-select"><option value="test">Выберите…</option><option value="SAS">SAS </option><option value="SATA-II">SATA-II</option></select></div><div id="hdd-controls-wrap"></div>');
				$("#hdd-wrap").append(typeSelect);

				$("#hdd-type-select").change(function(){
					var hdd_type = $(this).val();
					$("#hdd-controls-wrap").html("");

					for( var i=0; i < slots; i++){
						var element = '<div><label for="hdd-select-' + i + '">' + (i + 1) + ' диск</label><select class="hdd_control" id="hdd-select-' + i + '">';
						var options = '<option value="0">Выберите…</option>';
						$.each(Oversun.Calculator.data.hdds, function( index, hdd ){
							if( hdd.hdd_type == hdd_type ){
								options += '<option value="' + hdd.id + '">' + hdd.name + '</option>';
							}
						});
						element += options;
						element += '</select></div>';
						$("#hdd-controls-wrap").append($(element));
					};
				});

				$("#hdd-wrap").show();
			},

			memory: function( platformId ){
				var slots = Oversun.Calculator.data.platforms[platformId].memory_slots;
				var memory_type = Oversun.Calculator.data.platforms[platformId].memory_type;
				$("#memory-wrap").html("");

				for( var i=0; i < slots; i++){
					var element = '<div><label for="memory-select-' + i + '">' + (i + 1) + ' слот памяти</label><select class="memory_control" id="memory-select-' + i + '">';
					var options = '<option value="0">Выберите или оставьте слот пустым</option>';
					$.each(Oversun.Calculator.data.memory, function( index, memory ){
						if( memory.memory_type == memory_type ){
							options += '<option value="' + memory.id + '">' + memory.name + '</option>';
						}
					});
					element += options;
					element += '</select></div>';
					$("#memory-wrap").append($(element));
				};
				$("#memory-wrap").show();
			},

			processor: function( platformId ){
				var platformSocket = Oversun.Calculator.data.platforms[platformId].socket;

				var options = '<option value="0">Выберите…</option>';
				$.each(Oversun.Calculator.data.processors, function( index, processor ){
					if( processor.socket == platformSocket ){
						options += '<option value="' + processor.id + '">' + processor.name + '</option>';
					}
				});

				$('#processor-select').html(options);
				$('#processor-wrap').show();
			},

			platform: function(){

				var options = '<option value="0">Выберите…</option>';
				// add options
				$.each(Oversun.Calculator.data.platforms, function( index, platform ){
					options += '<option value="' + platform.id + '">' + platform.name + '</option>';
				});

				$('#platform-select').change(function(){
					//if($(this).val() != 0){
						Oversun.Calculator.helpers.processor($(this).val());
						Oversun.Calculator.helpers.memory($(this).val());
						Oversun.Calculator.helpers.hdd($(this).val());
						Oversun.Calculator.showPrice();
					//}
				});

				$('#platform-select').html(options);
				$('#platform-wrap').show();
			}
		},

		//
		// Methods

		reset: function(){
			$('#platform-select').html('<option value="0">Выберите…</option>');
			$('#processor-select').html('<option value="0">Выберите…</option>');
			$('#memory-wrap').html('');
			$('#hdd-wrap').html("");


			$('#result').hide();

			Oversun.Calculator.hide();
			Oversun.Calculator.helpers.platform();
		},

		hide: function(){
			$(".calc-hidden").hide();
		},

		showPrice: function(){
			var price = 0;
			if($('#platform-select').val() > 0){
				price += Oversun.Calculator.data.platforms[$('#platform-select').val()].price;
			}

			if($('#processor-select').val() && price > 0){
				price += Oversun.Calculator.data.processors[$('#processor-select').val()].price;

				if($('#processor-double').attr('checked')){
						price += Oversun.Calculator.data.processors[$('#processor-select').val()].price;
				}
			}

			$.each($('.memory_control'), function( index, memory_slot){
				if (price > 0)
					price += Oversun.Calculator.data.memory[$(memory_slot).val()].price;
			});

			$.each($('.hdd_control'), function( index, hdd_slot){
				if (price > 0)
					price += Oversun.Calculator.data.hdds[$(hdd_slot).val()].price;
			});

			var priceTotal = price * Oversun.Calculator.USD_COURCE / Oversun.Calculator.TIME_MULTIPLIER * 1.18;
			priceTotal =  Math.round(priceTotal / 100) * 100;

			$('#result').html('Итого: <b>' + priceTotal + '</b> руб. в месяц.').show();
			$('#reset-calc-link').show();
		},

		// Initializes the calculator.
		init: function(){

			// event handlers
			$('#reset-calc-link').click(function(){
				Oversun.Calculator.reset();
				$(this).hide();
			}).hide();

			$('#platform-select').live('change', Oversun.Calculator.showPrice);
			$('#processor-select').live('change', Oversun.Calculator.showPrice);
			$('#processor-double').live('click', Oversun.Calculator.showPrice);
			$('.hdd_control').live('change', Oversun.Calculator.showPrice);
			$('.memory_control').live('change', Oversun.Calculator.showPrice);


			// init process
			Oversun.Calculator.reset();
			Oversun.Calculator.hide();
			Oversun.Calculator.helpers.platform();
		}
	}
};

$(function(){
	$('html').addClass((
		($.browser.mozilla	&& parseFloat($.browser.version)<1.9)
		|| ($.browser.opera	 && parseInt($.browser.version)<10)
	) ? 'without_fontface' : '');


	window.faq_pseudo = $('.faq dt .pseudo');
	window.faq_pseudo_delay = 500;
	window.faq_toggle = function(e) {
		var o = $(e.currentTarget) || this;
		dt = $(o).parents('dt:eq(0)');
		is_show = $(o).is('.show');
		if(is_show) {
			dt.next().find('ins.img').animate({teleportIn:1}, 300);
			dt.find('ins.img').animate({teleportOut:1}, 300);
		} else {
			dt.next().find('ins.img').animate({teleportOut:1}, 300);
			dt.find('ins.img').animate({teleportIn:1}, 300);
		}
	}
	window.faq_pseudo_step = function(eq, timeout) {
		window.faq_toggle({currentTarget:window.faq_pseudo.eq(eq)});
		if(eq < window.faq_pseudo.length) setTimeout("window.faq_pseudo_step("+(eq+1)+", "+timeout+")", timeout);
	}


	window.faq_pseudo.click(window.faq_toggle);
	window.faq_pseudo_step(0, 400);

	$('.pseudo:has(.expand)').click(function() {
		setTimeout("window.faq_pseudo_step(0, 100)", 10);
	});

	if($("#calculator").length){
		Oversun.Calculator.init();
	}
});
