function showOrHide(obj, id)
{
	if(jQuery('#' + id).css('display') == 'none')
	{
		jQuery('#' + id).animate({height:'show'}, 300);
		jQuery(obj).text('Спрятать');
	}
	else
	{
		jQuery('#' + id).animate({height:'hide'}, 300);
		jQuery(obj).text('Показать');
	}
	
}
jQuery(document).ready(function(){
	jQuery('.showOrHideLink').each(function(){jQuery(this).show()}); 	
	jQuery('.showOrHideDivs').each(function(){jQuery(this).hide()}); 
});

if (navigator.userAgent.indexOf("Opera") >= 0 && navigator.userAgent.charAt(navigator.userAgent.indexOf("Opera")+6) < 9)
document.write("<style type='text/css'>@import url(/defa/css/op.css);</style>");

function showhide(id) {
    current = (document.getElementById(id).style.display == 'none') ? 'block' : 'none';
    document.getElementById(id).style.display = current;

    if (id == 'xxx2') {
        var div = document.getElementById('xxx1');

        if (div && (typeof(div) != 'undefined')) {
            if (current == 'none') {
                //div.style.backgroundImage = 'url(/defa/images/bg-xxx-s.png)';
                div.style.backgroundPosition = '100% 0';
            } else {
                div.style.backgroundPosition = '200% 0';
                //div.style.backgroundImage = 'none';
            }
        }
    }
}


/*     */

var interv; //,     
var t = 0; //  ""

function showhideSmooth(id) {
    current = jQuery('#' + id).width() == 0 || jQuery('#' + id).css('display') == 'none'  ? 'block' : 'none' ;//(document.getElementById(id).style.display == 'none') ? 'block' : 'none';
    var div = document.getElementById(id);
    var div_smooth_holder = document.getElementById(id + '_smooth_holder');

    if (div && (typeof(div) != 'undefined')) {
        if (div_smooth_holder && (typeof(div_smooth_holder) != 'undefined')) {
            div_smooth_holder.style.display = 'none';

            if (current == 'block') {

                div.style.width = '35px';
                div.style.display = 'block';
               // interv = setInterval('incW("' + id + '", 515)', 30);
			jQuery('#' + id).animate({width: '515'}, 1000, function(){jQuery('#' + id + '_smooth_holder').show();});
			
            } else {
			jQuery('#' + id).animate({width: '0'}, 1000);			 
              //  interv = setInterval('decW("' + id + '")', 30);
            }
        }
    }

    if (id == 'xxx2') {
        var div1 = document.getElementById('xxx1');

        if (div1 && (typeof(div) != 'undefined')) {
            if (current == 'none') {
                div1.style.backgroundPosition = '100% 0';
            } else {
                div1.style.backgroundPosition = '200% 0';
            }
        }
    }
}

function incW(id, maxW) {
    var div = document.getElementById(id);
    var div_smooth_holder = document.getElementById(id + '_smooth_holder');
    var slow = 5;
    var fast = 15;
    var w;

    /* TEST  */
        slow = fast;
    /* /TEST */

    if (div && (typeof(div) != 'undefined')) {
        if (t <= 400) {
            //w = countDx1(500);
            w = div.offsetWidth + slow;
        } else if (t >= 1100) {
            /*w = countDx2(1000);
            if (w <= div.offsetWidth) {
                w = div.offsetWidth + 10;
            }*/
            w = div.offsetWidth + slow;
        } else {
            w = div.offsetWidth + fast;
        }

        if (w <= maxW) {
            div.style.width = w + 'px';

            t += 30; // 10 
        } else {
            div.style.width = maxW + 'px';
            div_smooth_holder.style.display = 'block';

            window.clearInterval(interv);
            //alert('T = ' + t);
            t = 0;
        }
    }
}

function decW(id) {
    var div = document.getElementById(id);
    var slow = 5;
    var fast = 15;
    var w;

    /* TEST  */
        slow = fast;
    /* /TEST */

    if (div && (typeof(div) != 'undefined')) {
        if (t <= 400) {
            w = div.offsetWidth - slow;
        } else if (t >= 1100) {
            w = div.offsetWidth - slow;
        } else {
            w = div.offsetWidth - fast;
        }

        if (w > 35) {
            div.style.width = w + 'px';

            t += 30; // 10 
        } else {
            div.style.width = '0';
            div.style.display = 'none';

            window.clearInterval(interv);
            t = 0;
        }
    }
}

function countDx1(maxT) {
    if (t == maxT) {
        return 10;
    } else {
        return Math.round(-3000 / (t - maxT));
    }
}

function countDx2(minT) {
    var val;
    if (t == minT) {
        val = 10;
    } else {
        val = Math.round(-6000 / (t - minT) + 520)
        //alert(val);
    }

    return val
}

/* /    */

/* ========================================================================== */

function $(id) {
    var elem = document.getElementById(id);

    if (elem && (typeof(elem) != 'undefined')) {
        return elem;
    }
    return false;
}

function checkMail(lang) {
    var reMail = new RegExp('^[a-z][a-z0-9_\\-\\.]+@[a-z0-9_\\-\\.]+\\.[a-z]{2,}$', 'i');

    if ($('sf_EMAIL') && !reMail.test($('sf_EMAIL').value)) {
        if ($('subscr_err_msg')) {
            $('subscr_err_msg').style.display = 'block';
        } else {
            if (lang == 'en') {
                alert('Please, enter correct E-mail!');
            } else {
                alert('  E-mail!');
            }
        }
        return false;
    }

    return true;
}
