/* Functions */
function inputTitle(obj,bgClass) {
    $(obj)
    .bind('focus',
    function() {
        if (bgClass.length) {
            $(this).removeClass(bgClass)
        } else {
            if (this.value === this.getAttribute('title'))
                $(this).val('');
        }
    })
    .bind('blur',
    function() {
        if (!this.value.length) {
            if (bgClass.length)
                $(this).addClass(bgClass)
            else
                $(this).val(this.getAttribute('title'));
        }
    });
}

function openReadMore() {
    $('.readmore').click(function() {
        if ($(this).html().toLowerCase().indexOf('close') == '-1')
            $(this).html('close').attr('title','close').parent().find('p:eq(0)').height('auto').end();
        else
            $(this).html('read more').attr('title','read more').parent().find('p:eq(0)').height('50px').end();
        return false;
    });
}

function openMoreCap(section,span,tbl) {
        var anc = document.getElementById(section);
        var tblSpan = document.getElementById(tbl);
        var ancText = document.getElementById(span);
        if (anc.title.toLowerCase().indexOf('close') == '-1') {
            anc.title = 'Close';
            ancText.innerHTML = 'Close';
            anc.setAttribute("class", "close");
            anc.setAttribute("className", "close");
            tblSpan.style.display = 'block'; }
        else {
            anc.title = 'View More';
            ancText.innerHTML = 'View More';
            anc.setAttribute("class", "open");
            anc.setAttribute("className", "open");
            tblSpan.style.display = 'none'; }
        return false;
}

function openTab(tab) {
    tTab = document.getElementById(tab);
    var browserType = navigator.userAgent.toLowerCase();
    if (browserType.toLowerCase().indexOf('msie') != '-1') {
        tTab.click();
    }
    if (browserType.toLowerCase().indexOf('firefox') != '-1') {
        // for Firefox (currently debugging)
        loc = tTab.href;
        //alert(loc);
        document.location.href=loc;
    }
}

function hideSearchOptions() {
    $('.hidesearchoptions').click(function() {
        if ($(this).eq(0).html().toLowerCase().indexOf('show') == '-1')
            $(this).eq(0).html('Show search options').attr('title','Show search options').parent().find('.txtsearchin').hide().end();
        else
            $(this).eq(0).html('Hide search options').attr('title','Hide search options').parent().find('.txtsearchin').show().end();
        return false;
    });
}

function hoverHowToBuy() {
    $("a[@rel='howtobuy']").mouseover(function() {
        $(this).next('div:eq(0)').show().end();
    });
    $(".close").click(function() {
        $(this).parent().parent().parent().parent().find('div:eq(0)').hide().end();
        return false;
    });
}

function hoverInfo() {
    $("a[@rel='info']").hover(
    function(e) {
        $(this).before('<div class="box_info"><div class="box_info_top"><\/div><div class="box_info_content">' + $(this).next('div:eq(0)').html() + '<\/div><div class="box_info_bottom"><\/div><\/div>').end();
        $(this).parent().find('.box_info').css({marginTop: parseInt((-$('.box_info').height() / 2) + 5)}).show().end();
    },
    function() {
        $(this).parent().find('.box_info').remove().end();
    });
}

function hoverGold() {
    $("a[@rel='gold']").hover(
    function() {
        $(this).before('<div class="box_gold"><div class="box_gold_top"><\/div><div class="box_gold_content">' + $(this).parent().next('div:eq(0)').html() + '<\/div><div class="box_gold_bottom"><\/div><\/div>').end();
        $(this).parent().find('.box_gold').css({marginTop: parseInt((-$('.box_gold').height() / 2) + 5)}).show().end();
    },
    function() {
        $(this).parent().find('.box_gold').remove().end();
    });
}

function printPage() {
    $("a[@rel='print']").click(function() {
        self.print();
        return false;
    });
}
 
function applySiblingClass() {
    var activeNav = $("#activeSibling");

    if(activeNav != null)
    {
        var sibling = activeNav.next();
        
        if(sibling != null)
        {
            var nextSibling = sibling.next();

            if(nextSibling != null  && nextSibling.html() != null)
            {
                    sibling.addClass("middletop");
            }
            else
            {
                sibling.addClass("lasttop");
            }        
        }
    }
}
