$(document).ready(function() {
// Popup contacts
   var country = getCookie('country');
   if(country == undefined || country == '' || country == null) {
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() == 'UA') {
           setCookie('country', 'UA', 365);
           showContactsPopup('UA');
       }
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() == 'RU') {
           setCookie('country', 'RU', 365);
           showContactsPopup('RU');
       }
       if(typeof window['geoip_country_code'] == 'function' && geoip_country_code() != 'RU' && geoip_country_code() != 'UA') {
           setCookie('country', '', 365);
       }
       if(typeof window['geoip_country_code'] != 'function') {
          $.ajax(
          {
             url: 'geoip.php?action=get_country_code',
             success: function(data, textStatus, jqXHR){
                if(data.success){
                   setCookie('country', data.code, 365);
                   country = data.code;
                   showContactsPopup(country);
                }else{
                   setCookie('country', '', 365);
                }
             }
          }
          );
       }
   } else {
      showContactsPopup(country);
   }
//end
    // -- adding to favorites
    var browser = $.browser;
    if(browser.opera) {
        if ($("a#favorite").attr("rel") != "") {
            $("a#favorite").attr("rel","sidebar");
        }
	}
    $('a#favorite').click(function(event) {
        event.preventDefault();
        var title = document.title;
        var url = document.url;

        if (browser.mozilla) {
            window.sidebar.addPanel(title, url, '')
        } else if(browser.msie) {
            window.external.AddFavorite(url, title);
        } else if(browser.opera) {
            return false;
        } else {
            alert('Нажмите CTRL+D для добавления страницы в Закладки');
        }
    });
    // -- scrolling rates
    $('#undermenu').jCarouselLite({
        auto: 3000,
        speed: 1000,
        visible: 1,
        vertical: true
    })
    // -- flash icons
    for(var i = 1; i <= 8; i++) {
        $('#menu-icon' + i).flash({
            src: '/flash/icon' + i + '.swf',
            width: 55,
            height: 45,
            wmode: 'transparent',
            name: 'icon' + i,
            id: 'icon' + i
        });
    }
    // --telephone
    $('#hotLine').flash({
        src: '/flash/hotLine.swf',
        width: 203,
        height: 59
    });
    // --DowJones
    $('#dowjones').flash({
        src: '/flash/ban.swf',
        width: 203,
        height: 59
    });
});
/****/
function showContactsPopup(country) {
   if(country == undefined || country == '' || country == null) {
      return;
   }

   if(country != 'UA' && country != 'RU') {
      return;
   }

   country = country.toLowerCase();
   country = "ru";

   hidePopupContacts = getCookie(country + '_hide_contacts');
   
   if(hidePopupContacts != 1) {
      $('#contatcs_popup_' + country).show();
      $('#contatcs_popup_' + country + ' .kreuz').click(function(){
         $('#contatcs_popup_' + country).hide();
      });
      $('#contatcs_popup_' + country + ' > #clickable_popup').click(function(){
         window.location.href = 'http://ru.forex-mmcis.com/contact.html';
      });
      setCookie(country + '_hide_contacts', 1, 365);
   }
}
function setCookie(name,value,days) {
   if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
   }
   else var expires = "";
   document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
   var nameEQ = name + "=";
   var ca = document.cookie.split(';');
   for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
   return null;
}

function deleteCookie(name) {
   setCookie(name,"",-1);
}
/****/
function TabLeft()
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="180" height="425" id="right_menu" align="middle">\n');
	document.write('<param name="movie" value="/flash/right_menu.swf" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="bgcolor" value="#ffffff" />\n');
	document.write('<param name="play" value="true" />\n');
	document.write('<param name="loop" value="true" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="scale" value="showall" />\n');
	document.write('<param name="menu" value="true" />\n');
	document.write('<param name="devicefont" value="false" />\n');
	document.write('<param name="salign" value="" />\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<!--[if !IE]>-->\n');
	document.write('<object type="application/x-shockwave-flash" data="/flash/right_menu.swf" width="180" height="425">\n');
	document.write('<param name="movie" value="/flash/right_menu.swf" />\n');
	document.write('<param name="quality" value="high" />\n');
	document.write('<param name="bgcolor" value="#ffffff" />\n');
	document.write('<param name="play" value="true" />\n');
	document.write('<param name="loop" value="true" />\n');
	document.write('<param name="wmode" value="transparent" />\n');
	document.write('<param name="scale" value="showall" />\n');
	document.write('<param name="menu" value="true" />\n');
	document.write('<param name="devicefont" value="false" />\n');
	document.write('<param name="salign" value="" />\n');
	document.write('<param name="allowScriptAccess" value="sameDomain" />\n');
	document.write('<!--<![endif]-->\n');
	document.write('<a href="http://www.adobe.com/go/getflash">\n');
	document.write('<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Загрузить Adobe Flash Player" />\n');
	document.write('</a>\n');
	document.write('<!--[if !IE]>-->\n');
	document.write('</object>\n');
	document.write('<!--<![endif]-->\n');
	document.write('</object>\n');
}

// определяем броузер и систему
// опера может притворяться ИЕ...
var opera = Boolean(window["opera"]);
// IE или не IE, вот в чем вопрос
var MSIE = (navigator.appName.indexOf("Microsoft") != -1) && !opera;
// сунь или вынь?
var WIN = (navigator.userAgent.toLowerCase().indexOf("win") != -1);

// функция возвращает флэш-объект на странице
// (для Internet Explorer одним способом, для всех остальных - другим)
function getElement (id) {
    return MSIE ? window[id] : document[id];
}

function printID(name){
	var id = getElement(name);

	id.SetVariable('mess',1);
}
//простая функция, которая открывает попап и закрывает
/*
function mypopUp($num){
	var el = document.getElementById("contatcs_popup_ua");
	if($num==1) {
		el.style.cssText="display:block"; 
	}
else {
		el.style.cssText="display:none"; 
	}
}
*/
