$(document).ready(function () {

    //$.ajaxSetup({ cache: false });

    Cufon.replace('.sgp-b-cufon', {fontFamily: 'SohoGothicProBold'});
    Cufon.replace('.sgp-l-cufon', {fontFamily: 'SohoGothicProLight'});
    Cufon.replace('.sgp-m-cufon', {fontFamily: 'SohoGothicProMedium'});
    Cufon.replace('.sgp-r-cufon', {fontFamily: 'SohoGothicProRegular'});

    // oki widgets
    Cufon.replace('.oki-button-gray > span > span > b', {fontFamily: 'SohoGothicProMedium'});
    Cufon.replace('.oki-button-light > span > span > b', {fontFamily: 'SohoGothicProMedium'});
    Cufon.replace('.oki-button-light-leftarrow > span > span > b', {fontFamily: 'SohoGothicProMedium'});
    Cufon.replace('.oki-button-light-downarrow > span > span > b', {fontFamily: 'SohoGothicProMedium'});
    Cufon.replace('.oki-button-blue2 > span > span > b', {fontFamily: 'SohoGothicProMedium'});


    // find active menu link and mark it
    $('#top-menu > ul > li > a').each(function () {
        if ($(this).hasClass('active'))
            $(this).addClass('this-is-active');
    });

    // top menu cufon
    Cufon.replace('#top-menu > ul > li > a > span > span > b', {fontFamily: 'SohoGothicProRegular'});
    $('#top-menu > ul > li').hover(
        function () {
            $(this).find('> ul').fadeIn(50);

            // for active link do nothing
            if ($(this).find('> a').hasClass('this-is-active'))
                return;

            $(this).find('> a').addClass('active');

            var sp = $(this).find('> a > span > span > b');
            sp.css('color', '#353535').addClass('top-menu-redraw');
            Cufon.replace('#top-menu > ul > li > a > span > span  > b.top-menu-redraw', {fontFamily: 'SohoGothicProRegular'});
            sp.removeClass('top-menu-redraw');
        },
        function () {
            $(this).find('> ul').fadeOut(150);

            // if not active link remove hover effect
            if ( ! $(this).find('> a').hasClass('this-is-active')) {
                $(this).find('> a').removeClass('active');
            } else {
                return;
            }

            var sp = $(this).find('> a > span > span  > b');
            sp.css('color', '#ffffff').addClass('top-menu-redraw');
            Cufon.replace('#top-menu > ul > li > a > span > span  > b.top-menu-redraw', {fontFamily: 'SohoGothicProRegular'});
            sp.removeClass('top-menu-redraw');
        }
    );

    // fancy box gallery
    $("a.g-fancybox").fancybox({
      'transitionIn'    : 'elastic',
      'transitionOut'   : 'elastic',
      'speedIn'         : 600,
      'speedOut'        : 200,
      'overlayShow'     : true,
      'titleShow'       : false
    });

    /*
    $('#ss-photos').cycle({
        fx:      'fade',
        speed:   1000,
        timeout: 6000,
        pager:   '#ss-pager-links',
        prev:    '#ss-prev',
        next:    '#ss-next',
        pagerAnchorBuilder: function(idx, slide) { return '<a href="javascript:void(0)"><\/a>'; }
    });
    */
});

function troublesFaqCufonRedraw()
{
    Cufon.replace('#troubles-div .sgp-b-cufon', {fontFamily: 'SohoGothicProBold'});
}

function goTop()
{
    $('html, body').animate({scrollTop: 0}, 1000);
}


function isValidEmailAddress(emailAddress)
{
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function searchInCenegaSubmit()
{
    OkiClearDefValIn('search-in-cenega');
    document.forms['search-in-cenega'].submit();
}

function br2nl(str)
{
    return str.replace(/<br\s*\/?>/mg,"\n");
}

function removeNL(s)
{
    return s.replace(/[\n\r\t]/g, '');
}

function downloadWindow(link)
{
  window.open(link, "download", "menubar=no,width=530,height=460,toolbar=no,location=no,status=no");
}
