window.onresize = function() {
    Resize();
}
window.onload = function() {
    Resize();
}

var agent = navigator.userAgent.toLowerCase();
var major = parseInt(navigator.appVersion);
var minor = parseFloat(navigator.appVersion);

var isNN = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
var isNN4 = (isNN && (major == 4));
var isNN6 = (isNN && (major >= 5));

var isOPERA = agent.indexOf("opera")>-1 && window.opera;
var isIE4 = (agent.indexOf("msie") != -1 && !isOPERA);

var flash_version = 0; // ?????? ????-?????????????
var fz=0;
if (isIE4){
	ie = 1;
	for (var i=3; i<7; i++){
		try {
			if (eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+i+"')")) flash_version = i;
		}
		catch (e) {}
	}
}
if ((isOPERA || isNN || isNN4 || isNN6) && (navigator.plugins)){
	for (var i=0; i<navigator.plugins.length; i++){
		if (navigator.plugins[i].name.indexOf("Flash")> -1){
		    var descr = navigator.plugins[i].description;
		    var name = "Shockwave Flash";
		    var pos1 = descr.indexOf(' ', name.length);
		    var pos2 = descr.indexOf('.', pos1)
			fz = parseInt(descr.substr(pos1, pos2-pos1));
			if (fz > flash_version) flash_version=fz;
		}
	}
}

//-------------------------------------------------------------------//
function rusoft() {
  window.open('http://www.rusoft.ru');
}

function ShowHTTP(href, display, target, style, title) {
	if (display == '') display = href;
	if (target == '') target = '_blank';
	document.writeln('<a href="'+href+'" target="'+target+'" title="'+title+'" style="'+style+'">'+display+'</a>');
}

function ShowMail(user, domain1, domain2) {
	var email = user+'&#64;'+domain1+'&#46;'+domain2;
	if (ShowMail.arguments[3]) name = ShowMail.arguments[3];
	else name = email;
	document.writeln('<a href="mailto:'+email+'">'+name+'</a>');
}

function openImage(image) {
	if (image) window.open("/popup.php?img="+image, "popupimage", "scrollbars=no, resizable=1, width=100, height=100").focus();
	return false;
}

function openPhoto(id) {
	if (id) window.open("/popupf?id="+id, "popup", "scrollbars=1, resizable=1, width=700, height=450").focus();
}

function imgOpen(imgURL,imgWidth,imgHeight,Title) {
	var imgWndw=window.open('','_blank','width='+imgWidth+',height='+
	imgHeight+',toolbar=no,menubar=no,location=no,status=no,'+
	'resizable=yes,scrollbars=no');
	var imgTitle=(Title)?Title:imgURL+": "+imgWidth+'x'+imgHeight;
	with (imgWndw.document){
		open();
		write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
		'</he'+'ad><bo'+'dy leftmargin="0" '+
		' topmargin="0" '+
		'rightmargin="0" bottommargin="0" marginwidth="0" '+
		'marginheight="0"><img src="'+imgURL+'" width="'+imgWidth+
		'" height="'+imgHeight+'" border="0" alt="'+imgTitle+
		'"></bo'+'dy></ht'+'ml>');
		close();
	}
	return false
}

function OpenPopup(src) {
	if (arguments[1]) popup_name = arguments[1];
	else popup_name = 'popup';
	if (arguments[2]) popup_width = arguments[2];
	else popup_width = 500;
	if (arguments[3]) popup_height = arguments[3];
	else popup_height = 400;
	window.open(src, popup_name, 'toolbar=no,location=no,status=no,menubar=no,resizable=yes,directories=no,scrollbars=yes,width='+popup_width+',height='+popup_height).focus();
	return false
}

function SetCookie(sName, sValue){
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2070 23:59:59 GMT; path=/;";
}

function changeImage(id, img) {
	document.getElementById(id).src = img;
}

function insertFlash(v, fl, gif, lnk, w, h, id){
	if (flash_version >= v) {
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + w + '" height="' + h + '" id="flash' +  id + '" align="center"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + fl + '"><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="' + fl + '" wmode="transparent" quality="high" width="' + w + '" height="' + h + '"></embed></object>');
	} else if (gif != '') {
		document.write("<a href='"+lnk+"'><img src='"+gif+"' width='" + w + "' height='" + h + "' border=0></a>");
	}
}

function dropBlogCode() {
	$('a.blogCode').click(function(){
		$('.hiddenBlogCode').css('display', 'block');
	});

	$('.hiddenBlogCode .close').click(function(){
		$('.hiddenBlogCode').css('display', 'none');
	});
}

function buttonGallery() {
	var slideLi = $('#slideGallery li');
	if (slideLi.length <= 3) {
		$('.jcarousel-next-horizontal, .jcarousel-prev-horizontal').css('display', 'none');
	}
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // Format a number with grouped thousands
	//
	// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +	 bugfix by: Michael White (http://crestidg.com)

	var i, j, kw, kd, km;

	// input sanitation & defaults
	if( isNaN(decimals = Math.abs(decimals)) ){
		decimals = 2;
	}
	if( dec_point == undefined ){
		dec_point = ",";
	}
	if( thousands_sep == undefined ){
		thousands_sep = ".";
	}

	i = parseInt(number = (+number || 0).toFixed(decimals)) + "";

	if( (j = i.length) > 3 ){
		j = j % 3;
	} else{
		j = 0;
	}

	km = (j ? i.substr(0, j) + thousands_sep : "");
	kw = i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep);
	//kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).slice(2) : "");
	kd = (decimals ? dec_point + Math.abs(number - i).toFixed(decimals).replace(/-/, 0).slice(2) : "");


	return km + kw + kd;
}


$(document).ready(function () {
    current = $.cookie('currency');
    if (current != undefined)
        $('.currency').val(current);

    $('.currency').change(function () {
        val = $(this).val()-1;

        $('.currency').val(val+1);

        var old_currency = $.cookie('currency');
        if (old_currency == undefined)
            old_currency = 2;//USD - по умолчанию
        else
            old_currency -= 1;
        var multi = currency_list[old_currency].value / currency_list[val].value;
        $.cookie('currency', val+1, { expires: 0, path: '/'});

        $('.currencychange').each(
          function(){
              var str = $(this).html();
              var rv = parseFloat($(this).attr('rc'));
              var nv = rv * multi;
              $(this).attr('rc', nv);
              str = str.replace(new RegExp(" ",'g'), '');

              var from = parseInt(str);
              var need_name = Number(str);
              //var result = number_format(from*multi, 0, '', ' ');
              var result = number_format(nv, 0, '', ' ');
              if (isNaN(need_name))
                  result+=' '+currency_list[val].name;
              $(this).html(result);
          }
        );
    });
});

function showSaleForm() {
    $('#twoweeks, #twomonth, #onemonth').click(function(){
        $('#saleform').show();
        $('#saleformcataloges').hide();
    });
    $('#threemonth').click(function(){
        $('#saleform').hide();
        $('#saleformcataloges').show();
    });
}

function Resize() {
    if (document.getElementById('for_width').offsetWidth > 1008) {
        document.getElementById('hidden').style.display = 'block';
    }
    else {
        document.getElementById('hidden').style.display = 'none';
    }
    return true;
}

function slideGallery_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

