﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4-vsdoc.js" />

$(function() {
    cufon();
    mainHeader();
    hotLinks();
    mainQuickSearch();
    joinOurNewsletter();

    $('#homeNav').hide();
    $('#mainNav').hide();
});

$(window).load(function() {
    homeNav();
    mainNav();
});

function cufon() {
    Cufon.replace('#homeNav > ul > li > a', { hover: 'true' });
    Cufon.replace('#mainNav > ul > li > a', { hover: 'true' });
    Cufon.replace('.homeMainTitle');
    Cufon.replace('.homeSubTitle');
    Cufon.replace('#homeLearnAboutProcedures h2, #homeLasikNews h2');
    Cufon.replace('.HotLinks h3');
    Cufon.replace('#homeNewsletter h2');
    Cufon.replace('.yourFinanceOptions h3');
    Cufon.replace('#sectionHeading');
    Cufon.replace('#sectionIntro');
    Cufon.replace('.sectionSubHeading span');
    Cufon.replace('.MainPromotion h3, .MainPromotion h5');
}

function mainHeader() {
    var URL = document.URL.toLowerCase();
    
    if (URL.indexOf('/whylsca/') != -1) {
        $('#mainHeader').addClass('whyChooseUs');
    }
    else if (URL.indexOf('/eyehealth/') != -1) {
        $('#mainHeader').addClass('howEyesWork');
    }
    else if (URL.indexOf('/treatmentoptions/') != -1) {
        $('#mainHeader').addClass('treatmentOptions');
    }
    else if (URL.indexOf('/expectations/') != -1) {
        $('#mainHeader').addClass('expectations');
    }
    else if (URL.indexOf('/eligibilitycost/') != -1) {
        $('#mainHeader').addClass('eligibilityAndCost');
    }
    else if (URL.indexOf('/locations/') != -1) {
        $('#mainHeader').addClass('locations');
    }
    else if (URL.indexOf('/bookingsinfo/') != -1) {
        $('#mainHeader').addClass('bookingsAndInfo');
    }
}

function homeNav() {
    $('#homeNav').fadeIn();

    var TotalLIWidth = 0;
    $('#homeNav > ul > li').each(function(index) {
        TotalLIWidth += $(this).outerWidth();
        //TotalLIWidth += 10; // random number!
    });
    $('#homeNav > ul').css('width', TotalLIWidth + 'px');
    $('#homeNav > ul').css('margin', '0 auto');

    $('#homeNav > ul > li').mouseenter(function() {
        $(this).children('ul').stop(true, true).delay(250).slideDown();
    });
    $('#homeNav > ul > li').mouseleave(function() {
        $(this).children('ul').stop(true, true).delay(250).slideUp();
    });
}

function mainNav() {
    $('#mainNav').fadeIn();

    var TotalLIWidth = 0;
    $('#mainNav > ul > li').each(function(index) {
        TotalLIWidth += $(this).outerWidth();
        //TotalLIWidth += 10; // random number!
    });
    $('#mainNav > ul').css('width', TotalLIWidth + 'px');
    $('#mainNav > ul').css('margin', '0 auto');

    $('#mainNav > ul > li').mouseenter(function() {
        $(this).children('ul').stop(true, true).delay(250).slideDown();
    });
    $('#mainNav > ul > li').mouseleave(function() {
        $(this).children('ul').stop(true, true).delay(250).slideUp();
    });
}

function hotLinks() {
    $('.HotLinks ul li:odd').addClass('Alternate');
}

function mainQuickSearch() {
    var DefaultText = $('#mainQuickSearchFormItems INPUT#ucHotLinks_txtSearchKeywords').val();
    $('#mainQuickSearchFormItems INPUT#ucHotLinks_txtSearchKeywords').focus(function() {
        if ($(this).val() == DefaultText) {
            $(this).val('');
            $(this).addClass('HasText');
        }
    });
    $('#mainQuickSearchFormItems INPUT#ucHotLinks_txtSearchKeywords').blur(function() {
        if ($(this).val() == '') {
            $(this).val(DefaultText);
            $(this).removeClass('HasText');
        }
    });
}

function joinOurNewsletter() {
    var DefaultTextEmailAddress = $('#homeNewsletter #ucNewsletterBox_txtEmail').val();
    $('#homeNewsletter #ucNewsletterBox_txtEmail').focus(function() {
        if ($(this).val() == DefaultTextEmailAddress) {
            $(this).val('');
            $(this).addClass('HasText');
        }
    });
    $('#homeNewsletter #ucNewsletterBox_txtEmail').blur(function() {
        if ($(this).val() == '') {
            $(this).val(DefaultTextEmailAddress);
            $(this).removeClass('HasText');
        }
    });
}
