/*Function for cufon*/
Cufon.replace('.pri_nav li a, .search label, .hm_links li a, .content_section h1, .content_section h2, .content-area h2, .brochurenewmain h2, .juniper p, .gallerymain h2, .searchResultsmain h2, .rightmenu > ul > li > a > h3, .img-lib > div > p:first, .aboutusmain h2', { hover: true });
Cufon.replace('.content-area li a.collname, .productadd h3, .productbox .productinfo h3 a, a.productLink', { hover: true });
//Cufon.replace('.content_section ul li a', { hover: true });
Cufon.replace('#DesignDetails1_divAvailProducts h3 a, .tabs div ul li h3, .imggallery-area .categorytxt, .content1 .searchbox h3, .reviews h4', { hover: true });
//#DesignDetails1_rptComplProducts_ctl00_divProductadd h3 a,

/*Function for cufon*/
/*Function for background Fadeing*/
var timer;
var count;

$(document).ready(function() {

    dropdown('body');
    $(".pri_nav li a").hover(
	  function() {
	      Cufon.replace('.pri_nav li a', { hover: true });
	      Cufon.replace('.pri_nav li:hover a', { hover: true });
	  },
	  function() {
	      setTimeout(function() {
	          Cufon.replace('.pri_nav li a', { hover: true });
	      }, 100);
	  }
	);

    $('#accordion li a').click(function() {
        if ($(this).attr('class') != 'active') {
            $('#accordion li div').slideUp();
            $(this).next().slideToggle();
            $('#accordion li a').removeClass('active');
            $(this).addClass('active');
        }
    });
    $('#accordion li div').show();

    //

    /*  LHS expand collapes code
    $('.leftRhs ul li a').next().hide();
    $('.leftRhs ul li a').click(function(){			
    if($(this).next().css('display') == 'block'){
    $(this).removeClass('active');
    $(this).next().slideUp();
    }
    else if($(this).next().css('display') == 'none'){
    $(this).addClass('active');
    $(this).next().slideDown();
    }		
    });*/



    /* code for brochure-list-new page start  */
    if ($('.brochurenew').length != 0) {
        var broImgHtTotal = $('.imageThumbnail').length;
        for (var broImgHt = 0; broImgHt < broImgHtTotal; broImgHt++) {
            if ($('.brochureThumbnail img').eq(broImgHt).height() < 122) {
                var broImgHeight = $('.brochureThumbnail img').eq(broImgHt).height();
                var broImgMarTop = (122 - (broImgHeight)) / 2;
                $('.brochureThumbnail img').eq(broImgHt).css('margin-top', broImgMarTop);
            }
        }
    }
    /* code for brochure-list-new page end */


});

/*Faq Accordian script Starts*/
$(document).ready(function() {
    /*
    $('.faqs div h3').click(function(){
    if ($(this).attr('class') != 'active'){
    $('.faqs div div').slideUp();
    $(this).next().slideToggle();
    $('.faqs div h3').removeClass('active');
    $(this).addClass('active');
    }
    });
    */
    $('.faqs div h3').click(function() {
        $(this).next().slideToggle('fast');
        if ($(this).attr('class') == 'active') {
            $(this).removeClass('active');
        }
        else if ($(this).next().css('display', 'block')) {
            $(this).addClass('active');
        }
    });
});
/*Faq Accordian  script ends*/
/*var index = 1;
function slider() {
    clearTimeout(timer);
    index = index % count;
    doSuin(index);
    index++;
    timer = setTimeout("slider()", 6000);
}

function doSuin(index) {
    $("#bg ul li").fadeOut(1000);
    $("#bg ul li").eq(index).fadeIn(2000);
}*/
/*Function for background Fadeing*/
/*Function for footer expand
$(document).ready(function() {
    $('.footer_links').hide();
    $('.slide').click(function() {
        $('.footer_links').slideToggle(400);
        $('.slide').toggleClass("open");
        return false;
    });
});*/
/*Function for footer expand*/

$(function() {
    var offsetX = 20;
    var offsetY = 10;
    $('a.hover').hover(function(e) {
        var href = $(this).attr('href');
        $('<img id="largeImage" src="' + href + '" alt="image" />')
				.css({ 'top': e.pageY + offsetY, 'left': e.pageX + offsetX })
				.appendTo('body');
    }, function() {
        $('#largeImage').remove();
    });
    $('a.hover').mousemove(function(e) {
        $('#largeImage').css({ 'top': e.pageY + offsetY, 'left': e.pageX + offsetX });
    });
    $('a.hover').click(function(e) {
        e.preventDefault();
    });
});
/*Function for Refine Search expand*/
$(document).ready(function() {
    $('.refine-pnl').hide();
    $('.slide1').click(function() {
        $('.refine-pnl').slideToggle(400);
        $('.slide1').toggleClass("open");
        return false;
    });
});
/*Function for Refine Search expand close*/

/*Lightbox function start */
$(document).ready(function() {
    $(".zoombox").click(function() {
        var centerDiv = $('#zoomImageDiv');
        var height = $(window).height();
        var width = $(document).width();
        var left = width / 2 - (centerDiv.width() / 2);
        var top = height / 2 - (centerDiv.height() / 2)
        centerDiv.css({ 'left': left, 'top': top });
        $("#overlay").fadeIn();
        //$("#zoomImageDiv #expandedimage").attr("src" , "images/thumb" + index + "_zoom.jpg");
        $("#zoomImageDiv").fadeIn();
        $("select").hide();

    });

    $("#closeZoomDiv").click(function() {
        $("#overlay").fadeOut();
        $("select").show();
        $("#zoomImageDiv").fadeOut();
    });

});
/*Lightbox function end */

window.onload = function() {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
        /* HARD coding of the dropdown */
        if ($('#wtbTab2_ddlCountry_child').length != 0)
            ieDDcode('wtbTab2_ddlCountry_child', 'wtbTab2_ddlCountry_msa_', 'wtbTab2');

        if ($('#wtbTab3_ddlCountry_child').length != 0)
            ieDDcode('wtbTab3_ddlCountry_child', 'wtbTab3_ddlCountry_msa_', 'wtbTab3');

        if ($('#wtbEuropeDetails1_wtbTab_ddlCountry_child').length != 0)
            ieDDcode('wtbEuropeDetails1_wtbTab_ddlCountry_child', 'wtbEuropeDetails1_wtbTab_ddlCountry_msa_', 'wtbEuropeDetails1$wtbTab');
    }
}
function ieDDcode(DDdivTagID, DDaTagID, DDclickID) {
    var tatal = $('#' + DDdivTagID + ' a').length;
    for (var ieDD = 1; ieDD < tatal; ieDD++) {
        content1 = $('#' + DDdivTagID + ' a#' + DDaTagID + ieDD + ' span').html();
        content2 = "setTimeout('__doPostBack(\\'" + DDclickID + "$" + content1 + "\\',\\'\\')', 0)";
        $('#' + DDdivTagID + ' a#' + DDaTagID + ieDD).attr('onclick', content2);
    }
}


// Search box initialisation
// We should really only have one document ready
$(document).ready(function() {

    if ($("input.key_wrd").length) {
        $("input.key_wrd").autocomplete({
            source: "SearchAutocomplete.aspx", appendTo: '#menuContainer'
        });
        $("input.key_wrd").labelswitch();
    }

});

// Code for switching a text box's label
(function($) {

    $.fn.labelswitch = function() {
        return this.each(function() {
            var $this = $(this);

            function init() {
                $this.prev('label').hide();
                if ($this.val() == '' || $this.val() == $this.prev('label').text()) {
                    $this.addClass("empty");
                    $this.attr('label', $this.prev('label').text());
                    $this.val($this.prev('label').text());
                }
            }

            init();

            $this.focus(function() {
                var $t = $(this);
                if ($t.val() == "" || $t.val() == $t.attr('label')) {
                    $t.removeClass("empty");
                    $t.val("");
                }
            }).blur(function() {
                var $t = $(this);
                if ($t.val() == "") {
                    $t.val($t.attr('label'));
                    $t.addClass("empty");
                }
            });

        });
    };
})(jQuery);
//

(function($) {
    //Dropdown code
    $.fn.outerHTML = function(s) {
        return (s)
		? this.before(s).remove()
		: $('<select>').append(this.eq(0).clone()).html();
    }
})(jQuery);
function dropdown(sel_tab) {
    if ($(sel_tab).find('select').length != 0) {
        $(sel_tab).find("select").each(function() {
            if ($(this).parent().attr('class') != 'selectbg') {

                $(this).before("<div id='select_placeholder'></div>");
                var selectContent = $(this).outerHTML();
                var selectCSS = ''; //'height:' +$(this).height()+ ';width:' +$(this).width()
                $(this).remove();

                $("#select_placeholder").after('<div class="selectbg" style="' + selectCSS + '"><div class="selectedvalue"></div>' + selectContent + '</div>');
                $("#select_placeholder").remove();

            }
        }
		)
        $("select").each(function() {
            $(this).children("option").each(function() {
                if ($(this).attr("selected")) {
                    $(this).parent().prev(".selectedvalue").html($(this).html());
                }
            });
        });
        $("select").change(function() {
            $(this).prev().html($(this).val());
        });
    }
}
//


//Pradeep: Code to make footer sticky in Iphone

$(function () {

    var isIphone = (navigator.userAgent.indexOf('iPhone') > -1) ? true : false;

    /* iPad Footer Fixed - 23-11-11 - Part 1/3 - Start */
    var isIpad = (navigator.userAgent.indexOf('iPad') > -1) ? true : false;
    /* iPad Footer Fixed - 23-11-11 - Part 1/3 - End */

    //var isAndroid = (navigator.userAgent.indexOf('Android') > -1) ? true : false;
    var winHeight = $(window).height();

    function setFooterPos(scrollOffSet, isFirst) {
        //alert($('.footer').height())
        var expand_footer = 0;
        if ($('.footer').height() == 200) {
            expand_footer = -170;
        }
        var offest = 30;
        if (isFirst) offest = -offest;
        var newHeight = $(window).height() + scrollOffSet + offest + expand_footer;
        $('.footer').css('top', newHeight);
    }

    if (isIphone) {
        $('.footer').css({ position: 'absolute' });
        setFooterPos(0, true);

        //window.onorientationchange = function(){window.location.reload();};
        window.onscroll = function () {
            var scrollTop = $(document).scrollTop();
            if (scrollTop > 0)
                setFooterPos(scrollTop)
            else
                setFooterPos(0, true)
        }

        document.ontouchstart = function () { $('.footer').hide() }
        document.ontouchend = function () { $('.footer').delay(2000).show() }

    }
    /* iPad Footer Fixed - 23-11-11 - Part 2/3 - Start */
    else if (isIpad) {
        $('.footer').css({ position: 'fixed', bottom: 0 });
        $(window).scroll(function () { $(".footer").css("top", ($(window).height() + $(document).scrollTop() - $('.footer').height()) + "px"); });

        document.ontouchstart = function () { $('.footer').hide(); }
        document.ontouchend = function () {
            $('.footer').delay(2000).show(); $(window).scroll(function () { $(".footer").css("top", ($(window).height() + $(document).scrollTop() - $('.footer').height()) + "px"); });
        }
    }
    /* iPad Footer Fixed - 23-11-11 - Part 2/3 End */
    else {
        $('.footer').css({ position: 'fixed', bottom: 0 });
    }


    /*Footer Sliding*/
    $('.footer_links').hide();
    $('.slide').click(function () {
        $('.footer').toggleClass('expanded-footer');
        $('.footer_links').show(); //.slideToggle(400);
        $('.slide').toggleClass("open");

        /* iPad Footer Fixed - 23-11-11 - Part 3/3 - Start */
        if (isIpad) {
            $(".footer").css("top", ($(window).height() + $(document).scrollTop() - $('.footer').height()) + "px");
        }
        /* iPad Footer Fixed - 23-11-11 - Part 3/3 - End */

        if (isIphone) {
            var scrollTop = $(document).scrollTop();
            if (scrollTop > 0)
                setFooterPos(scrollTop)
            else
                setFooterPos(0, true)
        }


        return false;
    });

});

