/* Custom scripts for FV DW True 18/02/10 */

var isIE = false;

function closeOption(obj) {
    if (isIE) { $jq(optionsObj).hide(); return; }
    $jq(optionsObj).fadeOut('slow', function () {
        optionsObj.style.display = "none";
    });
}


function openOption(obj) {
    var pos = $jq(obj).offset();
    var width = $jq(obj).width();
    //show the menu directly over the placeholder
    $jq(optionsObj).css({ "left": (pos.left + width - 85) + "px", "top": pos.top - 30 + "px" });

    if (isIE) { $jq(optionsObj).show(); return; }

    $jq(optionsObj).fadeIn('slow', function () {
        // Animation complete.
    });
}

RollOverObj = new Object();
RollOverObjOpen = false;
objClicked = new Object();
lastObjClicked = new Object();
RollOverStr = "";

function openRollOver(obj, str) {
    if (ViewAllObjOpen) closeViewAll();
    objClicked = obj;
    RollOverStr = str;
    if (RollOverObjOpen) {
        $jq(RollOverObj).hide();
    }

    lastObjClicked = obj;
    RollOverObjOpen = true;

    var pos = $jq(obj).offset();
    var width = $jq(obj).width();
    RollOverObj = document.getElementById(str);
    $jq(RollOverObj).css({ "left": (pos.left + width + 10) + "px", "top": pos.top - 20 + "px" });

    if (isIE) {
        $jq(RollOverObj).show(0, function () {
            // Animation complete.
        });
        return;
    }

    $jq(RollOverObj).fadeIn('slow', function () {
        // Animation complete.
    });
}

function closeRollOver(obj) {
    if (ViewAllObjOpen) { closeViewAll(); }
    if (!RollOverObjOpen) return;
    if (isIE) {
        $jq(RollOverObj).hide();
        return;
        RollOverObjOpen = false;
    }

    $jq(RollOverObj).fadeOut('slow', function () {
        RollOverObj.style.display = "none";
        RollOverObjOpen = false;
    });
}

function floatOpen(obj, objName) {
    if (ViewAllObjOpen) closeViewAll();
    if (RollOverObjOpen) {
        $jq(RollOverObj).hide();
    }
    var pos = $jq(obj).offset();
    var width = $jq(obj).width();
    RollOverObjOpen = true;
    RollOverObj = document.getElementById(objName);
    $jq(RollOverObj).css({ "left": (pos.left + 5) + "px", "top": pos.top - 5 + "px" });
    if (isIE) {
        $jq(RollOverObj).show(0, function () {
            // Animation complete.
        });
        return;
    }

    $jq(RollOverObj).fadeIn('slow', function () {
        // Animation complete.
    });
}


var ViewAllObjOpen = false;
var scrollPos = 0;
ViewAllObj = new Object();
var footerWrapTop = 0;
var innerWrapperHeight = 0;
function openViewAll(obj, objName) {
    if (RollOverObjOpen) closeRollOver();
    ViewAllObjOpen = true;
    scrollPos = $jq(window).scrollTop();

    ViewAllObj = document.getElementById(objName);
    $jq(ViewAllObj).fadeIn('2000', function () {
        // Animation complete.
        var offset = $jq(".footerWrap").offset();
        innerWrapperHeight = $jq(".inner-wrapper").height();
        if (($jq(".scrollout").offset().top + $jq(".scrollout").height()) > innerWrapperHeight) {
            $jq(".inner-wrapper").height(($jq(".scrollout").offset().top + $jq(".scrollout").height() + 20));
        }
    });
}


function closeViewAll() {
    $jq('html,body').animate({ scrollTop: scrollPos }, '10000');

    ViewAllObjOpen = false;
    document.getElementById("viewAll").style.display = "block";
    document.getElementById("hideAll").style.display = "none";
    $jq(ViewAllObj).fadeOut('2000', function () {
        $jq(".inner-wrapper").height(innerWrapperHeight);
    });
}


function setNavs() {
    navLinks = document.getElementsByTagName("li");
    for (var i = 0; i < navLinks.length; i++) {
        if (navLinks[i].className == "nav-sofas-chairs") {
            navLinks[i].onmouseover = navOver;
        }
    }
}

var openSaveBoxObj = new Object();
var openSaveBoxOpen = false;

function openSaveBox(objName) {
    if (openSaveBoxOpen) return;
    openSaveBoxOpen = true;
    closeAll();
    openSaveBoxObj = document.getElementById(objName);
    $jq(openSaveBoxObj).fadeIn('2000', function () {
        // Animation complete.
    });

}

function closeSaveBox() {
    openSaveBoxOpen = false;
    $jq(openSaveBoxObj).fadeOut('2000', function () {
        // Animation complete.
    });

}

function navOver() {
    //alert(this);
}

currHeroObj = new Object();
currHeroLink = new Object();
var flashid = 1;
function swapHero(obj, x) {
    StopFlashMovie(flashid);
    flashid = x;
    $jq(currHeroLink).removeClass('hero-links hero-links-on');
    $jq(currHeroLink).addClass('hero-links');
    currHeroLink = obj;
    $jq(currHeroLink).addClass('hero-links hero-links-on');
    $jq(currHeroObj).fadeOut('2000', function () {
        // Animation complete.
    });
    currHeroObj = document.getElementById("hero-" + x);
    if (isIE) PlayFlashMovie(x);
    $jq(currHeroObj).fadeIn('2000', function () {
        // Animation complete.
    });
}


function StopFlashMovie(x) {
    var flashMovie = document.getElementById("flashid" + x);
    if (!flashMovie) return;
    if (flashMovie.stopFLV) {
        flashMovie.stopFLV();
        return;
    }

    if (flashMovie) {
        flashMovie.StopPlay();
        flashMovie.Rewind();
    }
}

function PlayFlashMovie(x) {
    var flashMovie = document.getElementById("flashid" + x);
    if (!flashMovie) return;
    if (flashMovie.startFLV) {
        flashMovie.startFLV();
        return;
    }
    if (flashMovie) {
        flashMovie.Play();
    }
}



function popUp(URL, w, h) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=" + w + ",height=" + h + ",left = 240,top = 212');");
}

/*
var ImageObjArray= new Array();
var ImageObjOnArray= new Array();
var rolloverArray=new Array();


rolloverArray=["tab-2.png","tab-3.png","tab-4.png","tab-5.png","tab-6.png"];

for (var i=0; i<rolloverArray.length;i++)
{
ImageObjArray[rolloverArray[i]]=new Image();
ImageObjOnArray[rolloverArray[i]]=new Image();
ImageObjArray[rolloverArray[i]].src="/images/"+ rolloverArray[i] + ".jpg";
ImageObjOnArray[rolloverArray[i]].src="/images/"+ rolloverArray[i] + "On.jpg";
}

*/
function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");

    if (MSIEOffset == -1) {
        return 0;
    } else {
        return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }
}

var sensitivityInt = 1;
var intervalInt = 10;
var timeoutInt = 10;
var usejs = true;
if (getIEVersionNumber() == 6) usejs = false;

window.onload = function () {

}

function initNav() {


    if (usejs) {

        $jq('.nav-sofas-chairs').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });

        $jq('.nav-dining').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });

        $jq('.nav-beds').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });

        $jq('.nav-bedroom-furniture').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });

        $jq('.nav-occasional').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });

        $jq('.nav-office').hoverIntent({
            sensitivity: sensitivityInt,
            interval: intervalInt,
            over: flyOut,
            timeout: timeoutInt,
            out: flyIn
        });
    }
}

function flyOut() {

    $jq(this).css({ backgroundPositionY: "-53px" }).children('a');
    $jq(this).children('.innerBlockWrap').css({ display: "block" });
    if (typeof closeAll == 'function')
    { closeAll(); }
}

function flyIn() {
    if ($jq(this).hasClass("tab-on")) $jq(this).css({ backgroundPositionY: "-106px" }); else
        $jq(this).css({ backgroundPositionY: "0px" });
    $jq(this).children('.innerBlockWrap').css({ display: "none" });
}


function loadjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

var midPromoObj = new Object();
var midPromoInt = 0;
var midPromoAnim = false;
var midPromoSpeed = 500;

function midPromoPrev() {
    if ($jq('div').is(':animated')) {
        return;
    }

    if (midPromoAnim) return;
    if (midPromoInt == 0) midPromoInt = promos.length;
    $jq(midPromoObj).customFadeOut(midPromoSpeed, function () {
        midPromoInt--;
        midPromoAnim = true;
        if (isIE) $jq(promos[midPromoInt]).customFadeIn(midPromoSpeed, function () { midPromoAnim = false; promos[midPromoInt].style.removeAttribute("filter"); });
        if (!isIE) $jq(promos[midPromoInt]).customFadeIn(midPromoSpeed, function () { midPromoAnim = false; });
        midPromoObj = promos[midPromoInt];
        $jq('img.bulletOn').removeClass('bulletOn').prev('img.bulletOff').addClass('bulletOn');
        if (midPromoInt == promos.length - 1) $jq('img.bulletOff:last').addClass('bulletOn');
        //window.status=midPromoInt;			
    });
}


function midPromoNext() {

    if ($jq('div').is(':animated')) {
        return;
    }

    if (midPromoAnim) return;
    $jq(midPromoObj).customFadeOut(midPromoSpeed, function () {
        if (midPromoInt == (promos.length - 1)) midPromoInt = 0; else midPromoInt++;
        midPromoAnim = true;
        if (isIE) $jq(promos[midPromoInt]).customFadeIn(midPromoSpeed, function () { midPromoAnim = false; promos[midPromoInt].style.removeAttribute("filter"); });
        if (!isIE) $jq(promos[midPromoInt]).customFadeIn(midPromoSpeed, function () { midPromoAnim = false; });
        midPromoObj = promos[midPromoInt];
        $jq('img.bulletOn').removeClass('bulletOn').next('img.bulletOff').addClass('bulletOn');
        if (midPromoInt == 0) $jq('img.bulletOff:first').addClass('bulletOn');
        //window.status=midPromoInt;		
    });
}


(function ($jq) {
    $jq.fn.customFadeIn = function (speed, callback) {
        $jq(this).fadeIn(speed, function () {
            if (jQuery.browser.msie)
                $jq(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };

    $jq.fn.customFadeOut = function (speed, callback) {
        $jq(this).fadeOut(speed, function () {
            if (jQuery.browser.msie)
                $jq(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });

    };

})(jQuery);

var cache = [];
(function ($jq) {

    // Arguments are image paths relative to the current page.
    $jq.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--; ) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage);
        }
    }
})(jQuery)

function swapPromo(obj) {
    alert(obj);
}

var currentSlide = 1;

function promoPrev() {
    $jq('#divscrollerWrap').cycle('prev');
    $jq('#divscrollerWrap').cycle('pause');

}

function promoNext() {
    $jq('#divscrollerWrap').cycle('next');
    $jq('#divscrollerWrap').cycle('pause');

}

var slideStart = false;
var selectObj = new Object();
function changed(i) {
    if (slideStart) {
        $jq(selectObj).removeClass('selectedon');
        selectObj = "promoSelect" + i.nextSlide;
        selectObj = document.getElementById(selectObj);
        $jq(selectObj).addClass('selectedon');
    }

    if (!slideStart) slideStart = true;

}

function setSitecore() {
    imgDivs = document.getElementsByTagName("img");
    for (var i = 0; i < imgDivs.length; i++) {
        if (imgDivs[i].src.search("~") > 0) {
            tmp = imgDivs[i].src.slice(imgDivs[i].src.indexOf("~"), imgDivs[i].src.length)
            tmp = "http://www.furniturevillage.co.uk/" + tmp;
            tmp = imgDivs[i].src = tmp;
        }
    }

    jQuery.get('css/offerpages.css', function (data) {
        tmp = data;
        //tmp=tmp.replace(/\/~\//gi, "http://www.furniturevillage.co.uk/~/");
        tmp = tmp.replace(/\/~\//gi, "http://gdm.furniturevillage.co.uk/~/");

        var head = document.getElementsByTagName('head')[0],
			style = document.createElement('style'),
			rules = document.createTextNode(tmp);
        style.type = 'text/css';
        if (style.styleSheet)
            style.styleSheet.cssText = rules.nodeValue;
        else style.appendChild(rules);
        head.appendChild(style);
    });
}


function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}


var sc = querySt("sc");

if (sc == "yes") {
    $(document).ready(function () {
        setSitecore();
        // alert(sc);
    });
}

//New functions June 2011 DTW

var basketAnimating = false;
var basketOpen = false;
var basketMouseIn = false;

function showSummary(remoteCaller) {

    $jq('.basket-summary').mouseleave(function () {
        closeSummary();
    });

    $jq('.basketContent').mouseenter(function () {
        basketMouseIn = true;
    });

    $jq('.basket').mouseleave(function () {
        if (basketOpen) {
            closeSummary();
        }
    });

    if (basketAnimating) return;

    goToTop();

    itemsNodes = $jq('.basketItemWrap').children();

    if (itemsNodes.length > 0 || remoteCaller != null) {

        if (remoteCaller != null) {
            $jq('.basketContent').css('display', 'none');
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(animateSummary);
            __doPostBack(remoteCaller, '');
            
            setTimeout('closeSummary(true)', 4000);
        } else {
            animateSummary();
        }
    }

    remoteCaller = null;
}

function animateSummary() {

    basketOpen = true;

    $jq('.basketContent').focus();

//    if (basketAnimating) return;
    basketAnimating = true;
    if (itemsNodes.length < 3) {

        $jq(".scrollUp").css({ display: 'none' });
        $jq(".topWrap").css({ height: '20px' });
        $jq(".scrollDown").css({ display: 'none' });
    }

    $jq(".basket-btn").css({ backgroundPosition: "0px -30px" });

    heightTmp = (($jq('.basketItemWrap').children().length * 130) + 240);
    if (heightTmp > 600) heightTmp = 615;
    heightTmp = heightTmp + "px";
    $jq(".basket-summary").animate({ "height": heightTmp }, 300, function () {
        basketAnimating = false;
        basketOpen = true;
    });
    //basketInterval=setInterval ( "closeSummary()", 5000);

    //$jq('.basketContent').fadeIn(5000);

    Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(animateSummary);
}

function closeSummary(remoteClose) {

    if (remoteClose == true && basketMouseIn == true) {
        return;
    }

    if (itemsNodes.length > 0) {
        if (basketAnimating) return;
        basketAnimating = true;
        $jq(".basket-btn").css({ backgroundPosition: "0px 0px" });
        $jq('.basket-summary').animate({ height: '0px' }, 300, function () {
            $jq('.basket-summary').css({ 'display': 'none' });
            basketAnimating = false;
            basketOpen = false;
        });
    }

    basketMouseIn = false;
}

var currNode = 0;

function scrollDown() {

    itemsNodes = $jq('.basketItemWrap').children();

    if (itemsNodes.length == (currNode + 2)) return;
    tmp = $jq(itemsNodes[currNode]).height() + 5;
    tmp = "-=" + tmp + "px";
    currNode++;
    if (itemsNodes.length == (currNode + 2)) $jq(".scrollDown").css({ cursor: 'default', backgroundPosition: '0px -25px' });

    $jq(".basketItemWrap").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollUp").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });

}

function scrollUp() {

    itemsNodes = $jq('.basketItemWrap').children();

    if (currNode == 0) return;
    currNode--;
    if (currNode == 0) $jq(".scrollUp").css({ cursor: 'default', backgroundPosition: '0px -25px' });

    tmp = $jq(itemsNodes[currNode]).height() + 5;
    tmp = "+=" + tmp + "px";
    $jq(".basketItemWrap").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollDown").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });
}


jQuery.fn.center = function () {
    this.css("position", "absolute");
    this.css("top", ($jq(window).height() - this.height()) / 2 + $jq(window).scrollTop() + "px");
    this.css("left", ($jq(window).width() - this.width() * 2) / 2 + $jq(window).scrollLeft() + "px");
    return this;
}

function initBasket() {
    var basketInterval = 0;

    itemsNodes = $jq('.basketItemWrap').children();

    if (itemsNodes.length < 3) {

        $jq(".scrollUp").css({ display: 'none' });
        $jq(".topWrap").css({ height: '20px' });
        $jq(".scrollDown").css({ display: 'none' });
    }

    $jq('.basket-summary').mouseleave(function () {
        closeSummary();
    });

    $jq('.basketContent').mouseenter(function () {
        basketMouseIn = true;
    });

    $jq('.basket-summary').mouseleave(function () {
        if (basketOpen) {
            closeSummary();
        }
    });

    $jq(".updateBtn").hover(function () {
        $jq(this).attr("src", "/images/topnav/updateBtnOver.gif");
    }, function () {
        $jq(this).attr("src", "/images/topnav/updateBtn.gif");
    });

    $jq('.basket-inner').mouseenter(function () {
        showSummary();
    });

    function basketOver() {

    }

    var config = {
        over: function () { }, // function = onMouseOver callback (REQUIRED)
        timeout: 1500, // number = milliseconds delay before onMouseOut
        out: function () { } // function = onMouseOut callback (REQUIRED)
    };

    $jq(".basket-summary-inner").hoverIntent(config);

    //$jq(".basket-summary-inner").mousemove(function(e){
    //		clearInterval (basketInterval);
    //		basketInterval=setInterval("closeSummary()", 5000);
    //});
}

var currClass = "";
var currHistory = "";
var currHeight = 0;
var currWrapHeight = 0;

function openTalkToUs(layerInt) {

    if (layerInt != 'four') {
        $jq('.btn-submit-enquiry').css({ 'display': 'none' });
    }

    tmpHeight = eval("layer" + layerInt + "Height[0]");
    currWrapHeight = eval("layer" + layerInt + "Height[1]");
    currHeight = tmpHeight;
    $jq(".back-btn").css({ display: "none" });
    tmp = $jq(document).height() + "px";
    $jq('#talktousDiv').css({ height: tmp });
    currClass = ".layer-" + layerInt;
    $jq(currClass).addClass('layer-shown');
    $jq(".layer-shown").css({ display: "block" });
    $jq(".layer-shown").css({ height: (tmpHeight) + "px" });
    $jq('#talktousDiv').css({ display: "block" });

    $jq(".layer-bgdiv").css({ height: (currHeight) + "px" });
    //alert(tmpHeight+currWrapHeight);
    $jq(".talktous-inner").animate({ "height": (currWrapHeight) + "px" }, 500, function () {
        //alert("aa");
    });
    closeAll();
}

function closeTalkToUs() {
    $jq("#talktousDiv").animate({ "height": "0px" }, 250, function () {
        $jq('#talktousDiv').css({ display: "none" });
    });
    $jq(".talktous-inner").animate({ "height": "0px" }, 250, function () {
        $jq('.talktous-inner').css({ display: "none" });
        $jq(".layer-shown").css({ display: "none" });
        $jq(".layer-shown").removeClass('layer-shown');
        //$jq(currClass).addClass('layer-shown');
        //$jq('select[name=natureofenquiry] option[value=0]').attr('selected', 'selected');
        $jq('.nature > select ').val(0);
        selectEnquiry(true);
    });
}

function backTalkToUs() {
    //alert(currHistory);
    tmpclass = "layer-one";
    if (currHistory == "layer-four") tmpclass = "layer-three";
    tmp = tmpclass.replace(/-/g, '');
    tmp = eval(tmp + "Height[0]");
    swapLayer(tmpclass, tmp);
    if (tmpclass == "layer-one") $jq(".back-btn").css({ display: "none" });
}

var layeroneHeight;
var layertwoHeight;
var layerthreeHeight;
var layerfourHeight;

function swapLayer(layerStr, h, layerHistory) {

    $jq('.btn-submit-enquiry').css({ 'display': 'none' });

    $jq(".back-btn").css({ display: "block" });
    tmpLayer = "." + layerStr;
    currClass = tmpLayer;
    currHistory = layerHistory;
    $jq(tmpLayer).css({ height: "0px" });
    $jq(".layer-shown").animate({ "height": "0px" }, 500, function () {
        $jq('.layer-shown').css({ display: "none" });
        $jq(".layer-shown").removeClass('layer-shown');

        if (layerStr == "layer-one") {
            $jq('.talktous-inner').css({ height: (layeroneHeight[1]) + "px" });
        }

        if (layerStr == "layer-two") {
            $jq('.layer-form').css({ height: layertwoHeight[0] + "px" });
            $jq('.talktous-inner').css({ height: (layertwoHeight[1]) + "px" });
            $jq('.btn-submit-enquiry').css({ 'display': 'none' });
            $jq('.ddlNatureOfEnquiry').val(0);
            selectEnquiry(0);
        }

        if (layerStr == "layer-three") {
            $jq('.layer-callus').css({ height: layerthreeHeight[0] + "px" });
            $jq('.talktous-inner').css({ height: (layerthreeHeight[1]) + "px" });
        }
        if (layerStr == "layer-four") {
            $jq('.layer-callyou').css({ height: layerfourHeight[0] + "px" });
            $jq('.talktous-inner').css({ height: (layerfourHeight[1]) + "px" });
        }

        $jq(tmpLayer).animate({ "height": (h) + "px" }, 500, function () {
            $jq(tmpLayer).addClass('layer-shown'); $jq('.btn-submit-enquiry').css({ 'display': 'block' });
        });
    });
}

//function validateForm(str) {
//    $jq('.inputError').removeClass('inputError');
//    $jq('.labelError').removeClass('labelError');
//    $jq('.error').css({ 'display': 'none' });
//    if ($jq('input[name=firstname]').val() == "") {
//        $jq('input[name=firstname]').addClass('inputError');
//        tmpObj = $jq('input[name=firstname]');
//        $jq(tmpObj).closest('label').addClass('labelError');
//        $jq('.error').css({ 'display': 'block' });
//        $jq('.error').html('Please enter your name');
//        return;
//    }
//    $jq('.layer-form').html("<p class='thanks'>Thanks for entering your details, we will be in contact with you shortly.</p>");
//    $jq(".contact-form").animate({ "height": "200px" }, 500);
//    $jq(".layer-two").animate({ "height": "230px" }, 500);
//    $jq(".talktous-inner").animate({ "height": "380px" }, 500);
//}

function enquiryComplete() {

    $jq('.layer-form').html("<p class='thanks'>Thanks for your enquiry, we will be in contact with you shortly.</p>");

}

function enquiryError() {

    $jq('.layer-form').html("<p class='thanks'>Thanks for your enquiry, we will be in contact with you shortly.</p>");

}

function selectEnquiry(closing) {

    tmp = $jq('.ddlNatureOfEnquiry').val();

    var enqIndex = getEnqIndex(tmp);

    $jq('.reqInf').css({ 'display': 'block' });

    $jq('.btn-submit-enquiry').css({ 'display': 'none' });

    if (enqIndex == 0) {
        $jq('.enq1').css({ 'display': 'none' });
        $jq('.enq2').css({ 'display': 'none' });
        $jq('.enq3').css({ 'display': 'none' });
        $jq('.enq4').css({ 'display': 'none' });
        $jq('.enq3About').css({ 'display': 'none' });
        $jq(".layer-form").animate({ "height": "248px" }, 500);
        if (!closing) $jq(".talktous-inner").animate({ "height": "430px" }, 500);
        $jq('.reqInf').css({ 'display': 'none' });
    }

    if (enqIndex == 1) {
        $jq('.enq1').css({ 'display': 'block' });
        $jq('.enq2').css({ 'display': 'none' });
        $jq('.enq3').css({ 'display': 'none' });
        $jq('.enq4').css({ 'display': 'none' });
        $jq('.enq3About').css({ 'display': 'none' });
        $jq(".layer-form").animate({ "height": "528px" }, 500);
        $jq(".talktous-inner").animate({ "height": "680px" }, 500);
    }

    if (enqIndex == 2) {
        $jq('.enq1').css({ 'display': 'block' });
        $jq('.enq2').css({ 'display': 'block' });
        $jq('.enq3').css({ 'display': 'none' });
        $jq('.enq4').css({ 'display': 'none' });
        $jq('.enq1Comments').css({ 'display': 'none' });
        $jq('.enq1OrderRef').css({ 'display': 'none' });
        $jq('.enq3About').css({ 'display': 'none' });
        $jq('.storeSelect').css({ 'display': 'none' });
        $jq(".layer-form").animate({ "height": "478px" }, 500);
        $jq(".talktous-inner").animate({ "height": "630px" }, 500);
    }

    if (enqIndex == 3) {
        $jq('.enq1').css({ 'display': 'block' });
        $jq('.enq2').css({ 'display': 'none' });
        $jq('.enq3').css({ 'display': 'block' });
        $jq('.enq4').css({ 'display': 'none' });
        $jq('.enq1Comments').css({ 'display': 'none' });
        $jq('.enq1OrderRef').css({ 'display': 'none' });
        $jq('.enq3About').css({ 'display': 'block' });
        $jq('.storeSelect').css({ 'display': 'none' });
        $jq(".layer-form").animate({ "height": "478px" }, 500);
        $jq(".talktous-inner").animate({ "height": "630px" }, 500);
    }

    if (enqIndex == 4) {
        $jq('.enq1').css({ 'display': 'block' });
        $jq('.enq2').css({ 'display': 'none' });
        $jq('.enq3').css({ 'display': 'none' });
        $jq('.enq4').css({ 'display': 'block' });
        $jq('.enq1Comments').css({ 'display': 'none' });
        $jq('.enq1OrderRef').css({ 'display': 'none' });
        $jq('.enq3About').css({ 'display': 'none' });
        $jq('.storeSelect').css({ 'display': 'none' });
        $jq('.enq1enqdetails').css({ 'display': 'block' });
        $jq(".layer-form").animate({ "height": "478px" }, 500);
        $jq(".talktous-inner").animate({ "height": "630px" }, 500);
    }

    $jq('.validationSummary').css({ 'display': 'none' });
    $jq('.btn-submit-enquiry').css({ 'display': 'block' });
}

var _enquiryType = "";

function getEnqIndex(tmp) {

    _enquiryType = "";

    switch (tmp) {

        case '0':
            return 0;

        case 'aefbcc2e-b6ca-44e1-8001-e5a6fe3569ff':
            _enquiryType = "Price_promise";
            return 1;

        case 'd037f394-c1c2-4f2f-a428-a442044678c5':
            _enquiryType = "Product_enquiry";
            return 1;

        case '9082c894-108b-4a32-a92e-89c4551d91f9':
            _enquiryType = "Online_purchases_pre_delivery";
            return 1;

        case 'e9507f7d-5ebd-4d06-8443-b4a658f75fed':
            _enquiryType = "Store_purchases_pre_delivery";
            return 1;

        case '9370617c-7499-4b67-b9e0-a548d7b14224':
            _enquiryType = "After_delivery_care";
            return 1;

        case '8a4bf1e8-6096-4808-a2b0-1829c20282a5':
            _enquiryType = "Feedback";
            return 2;

        case 'f24d2eb7-7a84-451a-950e-6d6de08da467':
            _enquiryType = "Other_enquiries";
            return 3;

        case 'd618e825-25ac-4404-85cf-a3e9e3536542':
            _enquiryType = "Tempur_enquiry";
            return 4;

        default:
            return 0;
    }
}

function closeAll() {
    $jq('.divOpened').animate({ height: '0px' }, 400, function () {
        $jq('.basket-summary').css({ 'display': 'none' });
        basketAnimating = false;
        basketOpen = false;
    });
    $jq(".divOpened").removeClass('divOpened');
}


function displayCalendar() {
    $jq(".calendar").animate({ "height": "235px" }, 500, function () {

    });

}

function closeCalendar() {
    $jq(".calendar").animate({ "height": "0px" }, 500, function () {

    });

}

function goToTop() {

    $jq('html, body').animate({ scrollTop: 0 }, 'slow'); return false;

}

function setGridPromoHeight(gridContainer) {

    tmpObj = $jq(gridContainer);

    tmpObjStr = '#' + tmpObj.attr('id');

    var height = $jq(tmpObjStr).parent().parent().height();

    $jq(tmpObjStr + ', .gridPromoContainer div').height(height - 2 + 'px');

    $jq(tmpObjStr + ', .gridPromoContainer div').fadeIn(1500);
}


//product page thumbnails

var currThumbnailNode = 0;

function scrollThumbnailDown() {

    thumbnails = $jq('.ulZoomImages').children();

    if (thumbnails.length == (currThumbnailNode + 3)) {
        return;
    }

    tmp = $jq(thumbnails[currThumbnailNode]).height();
    tmp = "-=" + tmp + "px";

    currThumbnailNode++;

    if (thumbnails.length == (currThumbnailNode + 3)) {
        $jq(".scrollThumbnailDown").css({ cursor: 'default', backgroundPosition: '0px -25px' });
    }

    $jq(".productThumbnailItemWrap").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollThumbnailUp").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });
}

function scrollThumbnailUp() {

    thumbnails = $jq('.ulZoomImages').children();

    if (currThumbnailNode == 0) {
        return;
    }

    currThumbnailNode--;

    if (currThumbnailNode == 0) {
        $jq(".scrollThumbnailUp").css({ cursor: 'default', backgroundPosition: '0px -25px' });
    }

    tmp = $jq(thumbnails[currNode]).height();
    tmp = "+=" + tmp + "px";

    $jq(".productThumbnailItemWrap").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollThumbnailDown").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });
}

function initProductThumbnails() {

    currThumbnailNode = 0;

    thumbnails = $jq('.ulZoomImages').children();

    if (thumbnails.length <= 3) {

        $jq(".scrollThumbnailUp").css('display', 'none');
        $jq(".scrollThumbnailDown").css('display', 'none');
    }
}



//lightbox thumbnails

var currThumbnailNodeLB = 0;

function scrollThumbnailDownLB() {

    thumbnails = $jq('.ulZoomImagesLB').children();

    if (thumbnails.length == (currThumbnailNodeLB + 3)) {
        return;
    }

    tmp = $jq(thumbnails[currThumbnailNodeLB]).height();
    tmp = "-=" + tmp + "px";

    currThumbnailNodeLB++;

    if (thumbnails.length == (currThumbnailNodeLB + 3)) {
        $jq(".scrollThumbnailDownLB").css({ cursor: 'default', backgroundPosition: '0px -25px' });
    }

    $jq(".productThumbnailItemWrapLB").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollThumbnailUpLB").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });
}

function scrollThumbnailUpLB() {

    thumbnails = $jq('.ulZoomImagesLB').children();

    if (currThumbnailNodeLB == 0) {
        return;
    }

    currThumbnailNodeLB--;

    if (currThumbnailNodeLB == 0) {
        $jq(".scrollThumbnailUpLB").css({ cursor: 'default', backgroundPosition: '0px -25px' });
    }

    tmp = $jq(thumbnails[currNode]).height();
    tmp = "+=" + tmp + "px";

    $jq(".productThumbnailItemWrapLB").animate({ "top": tmp }, { duration: "slow" });
    $jq(".scrollThumbnailDownLB").css({ cursor: 'pointer', backgroundPosition: '0px 0px' });
}

function initProductThumbnailsLB() {

    currThumbnailNodeLB = 0;

    thumbnails = $jq('.ulZoomImagesLB').children();

    if (thumbnails.length <= 3) {

        $jq(".scrollThumbnailUpLB").css('display', 'none');
        $jq(".scrollThumbnailDownLB").css('display', 'none');
    }
}






