﻿(function($){$.fn.jqm=function(o){var p={overlay:50,overlayClass:'jqmOverlay',closeClass:'jqmClose',trigger:'.jqModal',ajax:F,ajaxText:'',target:F,modal:F,toTop:F,onShow:F,onHide:F,onLoad:F};return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};if(p.trigger)$(this).jqmAddTrigger(p.trigger)})};$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide')};$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow')};$.fn.jqmShow=function(t){return this.each(function(){$.jqm.open(this._jqm,t)})};$.fn.jqmHide=function(t){return this.each(function(){$.jqm.close(this._jqm,t)})};$.jqm={hash:{},open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);if(c.modal){if(!A[0])L('bind');A.push(s)}else if(c.overlay>0)h.w.jqmAddClose(o);else o=F;h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in{Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'")}}if(c.ajax){var r=c.target||h.w,u=c.ajax,r=(typeof r=='string')?$(r,h.w):$(r),u=(u.substr(0,1)=='@')?$(t).attr(u.substring(1)):u;r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h)})}else if(cc)h.w.jqmAddClose($(cc,h.w));if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);(c.onShow)?c.onShow(h):h.w.show();e(h);return F},close:function(s){var h=H[s];if(!h.a)return F;h.a=F;if(A[0]){A.pop();if(!A[0])L('unbind')}if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove()}return F},params:{}};var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version=="6.0"),F=false,i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i);f(h)},f=function(h){try{$(':input:visible',h.w)[0].focus()}catch(_){}},L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m)},m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return!r},hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function(){if(!this[c]){this[c]=[];$(this).click(function(){for(var i in{jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F})}this[c].push(s)})})}})(jQuery);
jQuery('html').addClass('js');

this.obj2str = function (o, pairSep, sep) {
	if(typeof o == 'string' && o.length)
		return o;
	var str = "";
	for (var i in o)
		str += (i + (sep||'=') + o [i] + (pairSep||'&'));
	str = str.substr (0, (str.length - 1));
	return str;
};
this.str2obj = function (s, pairSep, sep) {
	if(typeof s !== 'string' && !s.length)
		return s;
	var o = {};
	sep = sep||'=';
	var a = s.split(pairSep||'&');
	for(var i = 0, val=a[0]; i<a.length; i++, val=a[i])
		o[val.substr(0, val.indexOf(sep))] = val.substr(val.indexOf(sep)+sep.length);
	return o;
};
this.shiftoutArray = function (a, val) {
	var i = a.length;
	while (i --)
		if (a [i] == val)
			a = a.splice (i, i + 1);
	return a;
};
this.openWin = function (src, name, prop, txt) {
	var sw, sh;
	if (self.screen)
	{
		sw=screen.width;
		sh=screen.height;
	} else if (self.java)
	{
		var j=java.awt.Toolkit.getDefaultToolkit();
		var s=j.getScreenSize();
		sw=s.width;
		sh=s.height;
	};
	sw = sw||1024;
	sh = sh||768;
	var w = (prop ? prop.width : null)||sw/2;
	var h = (prop ? prop.height : null)||sh/2;
	var o = {
		resizable:'yes',
		status:'yes',
		scrollbars:'yes',
		directories:'no',
		location:'no',
		titlebar:'no',
		personalbar:'no',
		menubar:'no',
		width:w,
		height:h,
		left:((sw-w)/2),
		top:((sh-h)/2)
	};
	if(typeof prop == "object")
	{
		for(var i in prop)
			o[i] = ''+prop[i];
		prop = this.obj2str(o, ',');
	} else
		prop = prop||this.obj2str(o, ',');
	src = src||"about:blank";
	name = name ||"_blank";
	var win = window.open(src, name, prop);
	if(txt && win){
		win.document.write(txt);
	};
	return win;
};
this.openTxt = function (txt, target) {
	return this.openWin(null, target||'textPopup', null, txt);
};
this.openImg = function (src, alt, target) {
	alt = alt || '';
	var winW = 250;
	var winH = 150;
	var str = '<html>';
	str += '<head><title>' + alt + '</title></head>';
	str += '<body onclick="window.close();" style="margin:0;padding:0;text-align:center;">Загружается картинка...</body></html>';
	var win = this.openWin('about:blank', target||"astrostar_picture_popup", {width:winW, height:winH}, str);
	var f = function(){
		var w = i.width;
		var h = i.height;
		win.document.body.innerHTML='';
		win.document.body.style.overflowY = 'hidden';
		win.moveBy((winW - w)/2, (winH - w)/2);
		win.resizeBy(w, h);
		win.document.body.innerHTML = '<img src="'+src+'" alt="'+alt+'" title="'+alt+'" style="display:block;margin:0 auto;border:0;"/>';
		win.resizeBy(-winW, -winH);
	};
	var i = win.document.createElement('img');
	i.onload = function(){
		if(!win) {
			return;
		}
		setTimeout(f, 13);
	};
	i.onerror = function(){
		if(!!win) {
			win.close();
		}
		alert('Ошибка загрузки картинки.');
	};
	i.style.position = 'absolute';
	i.style.left = i.style.top = '-99999em';
	i.src = src;
	win.document.getElementsByTagName('body')[0].appendChild(i);
/**/
	return win;
};

jQuery(document).ready(function($) {
	$('#index_intro A').hover(function(e){
		e.preventDefault();
		var t = $(this);
		$('#index_intro_hint').css({left:e.pageX, top:e.pageY}).find('DIV.index_intro_hint_content').text(t.attr('title')).end().show();
	}, function(e){
		$('#index_intro_hint').hide();
	}).mousemove(function(e){
		$('#index_intro_hint').css({left:e.pageX, top:e.pageY});
	});
	var html = $('#order FORM').html();
	$('#choke').jqm({trigger:'A.choke'});
	$('#order').jqm({onHide: function(hash){
		hash.w.hide();
		hash.o.remove();
		$('#order FORM').html(html);
	}}).find('form').submit(function(){
		var data = $(this).serialize();
		var f = $(this).html('<p>Спасибо за Ваш заказ.<p>');
		/*$.ajax({
			url: f.attr('action'), 
			data: data,
			success: function(data){
				f.text('<p>'+data+'</p>');
			},
			error: function(e){
				f.text('<p>'+e.message+'</p>');
			}
		});/**/
		return false;
	});
});
