﻿function setBigImg(big_img_class, small_img_class, duration) {
    $(small_img_class).mouseenter(function () {
        var selected = $(this).parent('a');
        if ($(big_img_class).attr('src') != selected.attr('href')) {
            $(big_img_class).stop().fadeOut(duration, function () {
                $(big_img_class).attr('src', selected.attr('href'));
                $(big_img_class).attr('title', selected.parent('a').attr('title'));
                $(big_img_class).attr('alt', selected.attr('alt'));
                $(big_img_class).parent('a').attr('href', selected.attr('src'));
                $(big_img_class).parent('a').attr('title', selected.parent('a').attr('title'));
                $(this).fadeTo(duration, 1, function () {
                    GLO_active = false;
                });
            });
        }
    });
}

function keyPressedEnter(id, url_redirect) {
    $(id).keypress(function (e) {
        if (e.keyCode == '13') {
            location.href = url_redirect + $(id).val();
            return false;
        }
    });
}

function keyPressedEnterRef(id) {
    $(id).keypress(function (e) {
        if (e.keyCode == '13') {
            location.href = "resultats-vente+location-ref-blois-" + $(id).val() + "-0-0.aspx";
            return false;
        }
    });
}

function getPage() {
    var url = window.location.toString();
    //alert(typeof(url));
    var urlparts = url.split('/');
    var url_get = urlparts[urlparts.length - 1].split('?')
    return url_get[0];
}

$(document).ready(function () {
    var page = getPage();
    //$('#footer').html(page.indexOf('details'));
    if (page.indexOf('details') != -1) {
        setBigImg('.big_image_detail', '.small_image_detail', 300);
        $("a.big_image_lien").fancybox();
        $("a.small_image_lien").fancybox();
        $(".fancybox").fancybox();
    } else if (page == 'Default.aspx' || page == '' || page == '/') {
        keyPressedEnterRef('#ctl00_MainContent_TBReference');
        $(".fancybox").fancybox();
    }
})
