//// fix for IE hover problem (for dropdown menu)
sfHover = function() {
    var navEl = document.getElementById("nav");
    if (navEl != null) {
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i = 0; i < sfEls.length; i++) {
            sfEls[i].onmouseover = function() {
                this.className += " sfhover";
            }
            sfEls[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function CloseFancy() {
    parent.$.fancybox.close();
}

function CloseFancyByTime(miliseconds) {
    var Timeout = setTimeout("CloseFancy()", miliseconds);
}

//function Confirm(labelMessage, title, buttonClientID) {
//    jConfirm(labelMessage, title, function(r) {
//        if (r) $('#' + buttonClientID).click();
//    });
//}

function Confirm(labelMessage, title, buttonClientID) {
    jConfirm(labelMessage, title, function(r) {
        if (r) $('#' + buttonClientID).click();
    });
}

jQuery.fn.limitMaxlength = function(options) {

    var settings = jQuery.extend({
        attribute: "maxlength",
        onLimit: function() { },
        onEdit: function() { }
    }, options);

    // Event handler to limit the textarea
    var onEdit = function() {
        var textarea = jQuery(this);
        var maxlength = parseInt(textarea.attr(settings.attribute));

        if (textarea.val().length > maxlength) {
            textarea.val(textarea.val().substr(0, maxlength));

            // Call the onlimit handler within the scope of the textarea
            jQuery.proxy(settings.onLimit, this)();
        }

        // Call the onEdit handler within the scope of the textarea
        jQuery.proxy(settings.onEdit, this)(maxlength - textarea.val().length);
    }

    this.each(onEdit);

    return this.keyup(onEdit)
        .keydown(onEdit)
        .focus(onEdit);
}

function showTab(flag) {
    $('#prices').css('display', (flag == "prices") ? "block" : "none");
    $('#properties').css('display', (flag == "properties") ? "block" : "none");
    if ($('#options') != undefined) { $('#options').css('display', (flag == "options") ? "block" : "none"); }

    $('#tabs li').each(function(i) {
        $(this).removeClass('current');
        if (i == 0 && flag == "prices") $(this).addClass('current');
        if (i == 1 && flag == "properties") $(this).addClass('current');
        if ($('#options') != undefined) { if (i == 2 && flag == "options") $(this).addClass('current'); }
    });
}

$(document).ready(function() {
    //general
    $("a[rel=lightbox]").fancybox({ 'autoScale': true });
    $(".fancybox").fancybox({ 'width': 850, 'height': 500 });
    $(".fbiframe").fancybox({ 'autoScale': true, 'type': 'iframe', 'width': 880, 'height': 500 });
    
    //Personalisation
    $('#btnNew').click(function() {
        $('#NewBtn').hide('slow');
        $('#NewC').show('fast');
    });
    $('#btnCancel').click(function() {
        $('#NewC').hide('slow');
        $('#NewBtn').show('fast');
    });
    
    //Signin
    $(".forgotfb").fancybox({ 'width': 560, 'height': 190, 'autoScale': false, 'transitionIn': 'none', 'transitionOut': 'none', 'type': 'iframe' });

    //product detail
    $(".imgdetail").fancybox({ 'autoScale': true, 'titleShow': false });
    
    //Advanced search
    $('.advsl').click(function() {
        if ($('.searchbt1').css('display') == 'none') {
            $('#advs').hide('fast');
            $('.searchbt1').show();
            $(this).removeClass('sup').addClass('sdown');
        }
        else {
            $('.searchbt1').hide();
            $('#advs').show("fast");
            $(this).removeClass('sdown').addClass('sup');
        }
    });
});  

