/*
*	bosch.js
*
*	bosch
*/

// carousel AutoRun function
function autoCarousel() { $("#carouselRight").trigger("click"); };

//carousel AutoRun function runs here
if ($("#carousel").length > 0) { var CarouselInterval = setInterval(function () { autoCarousel() }, 6000); }

// Stop Auto carousel
function stopCarousel() { clearInterval(CarouselInterval); }


// CDB Carousel
// carousel AutoRun function
function autoCDBCarousel() { $("#cdb_carouselRight").trigger("click"); };

//carousel AutoRun function runs here
if ($("#cdb_carousel").length > 0) { var CDBCarouselInterval = setInterval(function () { autoCDBCarousel() }, 6000); }

// Stop Auto carousel
function stopCDBCarousel() { clearInterval(CDBCarouselInterval); }

function alignCDBCarousel() {
    itemCount = $("#cdb_carouselOverflow .teaser-type-2").length;
    if (itemCount < 6) {
        setTimeout("stopCDBCarousel()", 500);
        $("#cdb_carouselLeft, #cdb_carouselRight").addClass("disabled");

        cWidth = 0;
        $("#cdb_carouselOverflow .teaser-type-2").each(function () {
            cWidth = cWidth + $(this).outerWidth();
        });
        setTimeout(function () {

            $("#cdb_carouselOverflow .teaser-type-2:last").prev().find("h5").trigger("click");

        }, 500)
    };
    setTimeout(function () {
        $("#cdb_carousel, #cdb_carouselLeft span, #cdb_carouselRight span").css("visibility", "visible");
    }, 100);

    cWidth = 0;
    $("#cdb_carouselOverflow .teaser-type-2").each(function () {
        cWidth = cWidth + $(this).outerWidth();
    });
    $("#cdb_carouselOverflow").width(cWidth);

    if (itemCount >= 6) {
        $("#cdb_carouselLeft, #cdb_carouselRight").removeClass("disabled");
        caroleftEnd = -123 * (itemCount - 5);
        //$("#cdb_carouselOverflow").css("left", caroleftEnd);

        $("#cdb_carouselOverflow").animate({
            left: caroleftEnd
        }, { duration: 1000, queue: true, complete: function () {
            $("#cdb_carouselOverflow .teaser-type-2:last").prev().find("h5").trigger("click");
            $("#cdb_carouselRight").addClass("disabled");
        }
        })

        $("#cdb_carouselRight").addClass("disabled");
    }

    $("#cdb_carouselOverflow .teaser-type-2:last").css("background", "none");
}

// FAQ Carousel
// carousel AutoRun function
function autoFAQCarousel() { $("#faq_carouselLeft").trigger("click"); };

//carousel AutoRun function runs here
if ($("#faq_carousel").length > 0) { var FAQCarouselInterval = setInterval(function () { autoFAQCarousel() }, 6000); }

// Stop Auto carousel
function stopFAQCarousel() { clearInterval(FAQCarouselInterval); }

function alignFAQCarousel() {
    itemCount = $("#faq_carouselOverflow .teaser-type-2").length;
    if (itemCount < 6) {
        setTimeout("stopFAQCarousel()", 500);
        $("#faq_carouselLeft, #faq_carouselRight").addClass("disabled");

        cWidth = 0;
        $("#faq_carouselOverflow .teaser-type-2").each(function () {
            cWidth = cWidth + $(this).outerWidth();
        });
        setTimeout(function () {

            //$("#faq_carouselOverflow .teaser-type-2:first").prev().find("h5").trigger("click");
            $('#faq_carousel .teaser-type-2[rel="' + $('#selectedfaq').val() + '"]').find('h5').trigger('click');
            //console.log($('#faq_carousel .teaser-type-2[rel="' + $('#selectedfaq').val() + '"]'));
            //$('#faq_carousel .teaser-type-2[rel="' + $('#selectedfaq').val() + '"]').prev().addClass('selectedBefore');

        }, 500)
    };
    setTimeout(function () {
        $("#faq_carousel, #faq_carouselLeft span, #faq_carouselRight span").css("visibility", "visible");
    }, 100);

    cWidth = 0;
    $("#faq_carouselOverflow .teaser-type-2").each(function () {
        cWidth = cWidth + $(this).outerWidth();
    });
    $("#faq_carouselOverflow").width(cWidth);

    if (itemCount >= 6) {
        $("#faq_carouselLeft, #faq_carouselRight").removeClass("disabled");
        caroleftEnd = -123 * (itemCount - 5);
        caroleftEnd = 0;
        var selectedFaqIndex = $('#faq_carousel .teaser-type-2[rel="' + $('#selectedfaq').val() + '"]').index() +1;
        if (selectedFaqIndex > 5) {
            caroleftEnd = -123 * (selectedFaqIndex - 5);
        } else {
            $("#faq_carouselLeft").addClass("disabled");
        }
        if (selectedFaqIndex == itemCount) {
            $("#faq_carouselRight").addClass("disabled");
        }
        //$("#cdb_carouselOverflow").css("left", caroleftEnd);

        $("#faq_carouselOverflow").animate({
            left: caroleftEnd
        }, { duration: 1000, queue: true, complete: function () {
            $('#faq_carousel .teaser-type-2[rel="' + $('#selectedfaq').val() + '"]').find('h5').trigger('click');
        }
        })

        //$("#faq_carouselLeft").addClass("disabled");
        

    }

    

    //$("#faq_carouselOverflow .teaser-type-2:first").css("background", "none");
}


// News Auto Ticker function
function autoTicker() { $("#tickerRight").trigger("click"); };

//News Auto ticker function runs here
if ($("#tickerRight").length > 0) { var TickerInterval = setInterval(function () { autoTicker() }, 5000); };

// Stop Auto ticker
function stopTicker() { clearInterval(TickerInterval); }



//clear selected Text

function clearText() {
    if (window.getSelection) {
        if (window.getSelection().empty) {  // Chrome
            window.getSelection().empty();
        } else if (window.getSelection().removeAllRanges) {  // Firefox
            window.getSelection().removeAllRanges();
        }
    } else if (document.selection) {  // IE?
        try {
            document.selection.empty();
        } catch (e) {
            //die ie
        }
    }
}


//querystring reader
function $get(key, url) {
    if (arguments.length < 2) url = location.href;
    if (arguments.length > 0 && key != "") {
        if (key == "#") {
            var regex = new RegExp("[#]([^$]*)");
        } else if (key == "?") {
            var regex = new RegExp("[?]([^#$]*)");
        } else {
            var regex = new RegExp("[?&]" + key + "=([^&#]*)");
        }
        var results = regex.exec(url);
        return (results == null) ? "" : results[1];
    } else {
        url = url.split("?");
        var results = {};
        if (url.length > 1) {
            url = url[1].split("#");
            if (url.length > 1) results["hash"] = url[1];
            url[0].split("&").each(function (item, index) {
                item = item.split("=");
                results[item[0]] = item[1];
            });
        };
        return results;
    };
};

function iefixes() {

	$('.title-info p').each(function () {
		if ($.trim($(this).text()) == "") {
			$(this).addClass("dpn");
		}
	});
	
	$("#footerNav ul").find("li:first a").css({ border: 0, padding: 0 });

	if ($.browser.msie) {
        if ($('.title-info').length > 0 && $('.title-info p').length > 0) {
            var maxPwidth = 0;
            $('.title-info p').each(function () {
            	if ($(this).width() > maxPwidth) {
            		maxPwidth = $(this).width();
            	}
            });
            if ($('.title-info a.roundbutton').outerWidth() > maxPwidth) {
                maxPwidth = $('.title-info a.roundbutton').outerWidth() + 10;
            };
            $('.title-info').width(maxPwidth);
        }
    };

   

    setTimeout(function () {
        $('.title-info').css("visibility", "visible");
    }, 100);
};


function SortBox() {
    var mLinks = $('.boxMorelink').length;
    if (mLinks) {
        $('.box').hover(function () {
        
		}, function () {
            var t = $(this);
            $(t).addClass('disable');
            return false;
        })
        $('.boxMorelink').hover(function () {
            var t = $(this);
            $(t).prev().removeClass('disable');
            return false;
        }, function () {
            
        })
    }
}




function toolTip() {
    var tips = $('.tip').length;
    var tip = $('.tip');
    var chInt = true;
	
	
    /*
    Tooltip
    */
    if (tips) {
        $(tip).each(function () {
            var p = $(this).parent();
            var t = $(this);
            var w = $(t).width();
            var h = $(t).height();
            var x = $(p).find('div.tipContainer');
            $(x).css({ 'top': h + 20, 'left': (w / 5) - 12, 'right': (w / 5) - 12 });

            //var content = $(x).html();
            //$(p).append('<div class="tooltip dpn" style="top:'+(h+20)+'px;left:'+(w/2-18)+'px"><div class="hoverArea"></div><span></span><div class="content">'+content+'</div></div>');	
        });
        $(tip).hover(function () {
			$('#footerRight .fRate').css({'position':'static'});
			// properties pictogramResultsheet
        	clearTimeout($.data(this, 'timeout'));
        	$.data(this, 'timeout', setTimeout($.proxy(function () {
        		var p = $(this).parent();
        		var th = $(this).parent().find('div.tipContainer');
        		// $('.sortBox .more-link').css({ 'position': 'static' });
        		$(p).css({ 'position': 'relative', 'zIndex': '5000' });

        		if ($(th).hasClass('intelligence')) {
        			var lists = '';
        			if (chInt) {
        				$('.online').block();
        				chInt = false;
        				var dataC = 0;
        				$.get('ChannelIntelligenceHandler.ashx', { skuId: $('input[type=hidden][id*=hiddenSKUid]').val(), tm: Math.random() }, function (d) {
        					if (typeof (d) != 'string') {
        						$(d).find('DEALER_ITEM').each(function () {
        							var id = $(this).find('DEALER_ID').text();
        							if (!id) {
        								return;
        							}
        							var th = '';
        							var bu = '';
        							bu = $(this).find('BUY_URL').text();
        							$(d).find('DEALER[id=' + id + ']').each(function () {
        								th = $(this);
        							})
        							if ($(th).find('DEALER_LOGO').text()) {
        								dataC++;
        								lists += '<li class=""> \
												<div class="fl logos">	\
													<a href="' + bu + '" target="_blank"> \
													<img src="' + $(th).find('DEALER_LOGO').text() + '" width="90" height="60" alt="" /> \
													</a> \
												</div> \
												<div class="fl">\
													<a href="' + bu + '" class="blueLink" target="_blank">' + $(th).find('PRODUCT_NAME').text() + '</a> \
													<span class="greenDot">In Stock</span>\
												</div>\
											</li>';
        							}

        						})

        						var ttimg = [];
        						$(d).find('DEALER_ITEM').each(function () {
        							ttimg.push($(this).find('TRUE-TAG').text());
        						})
        						$.each(ttimg, function (a, b) {
        							var ttimage = new Image(1, 1);
        							ttimage.src = b;
        							ttimage = null;
        						})
        						$('.onlineItems ul.channel').removeClass("dpn").html(lists);
        						if ($.trim($('.onlineItems ul.channel').html()) == "") {
        							$('.onlineItems ul.channel').addClass("dpn");
        						}
        						if (dataC) {
        							$('.intelligenceChannel').removeClass('dpn');
        						}
        						if ($.trim($('.onlineItems ul.hybris').html()) == "" && $.trim($('.onlineItems ul.channel').html()) == "") {
        							$(".intelligenceChannel").addClass("dpn");
        						}
        					} else {
        						// $('.intelligenceChannel').addClass('dpn');
        					}
        					$('.online').unblock();
        				}).error(function () {
        					chInt = true;
        					// $('.intelligenceChannel').addClass('dpn');
        					$('.online').unblock();
        				});
        			}
        		}


        		if (th.length > 0) {
        			$(th).removeClass('dpn');
        			if ($(th).offset().left + $(th).width() > $("#wrapper").offset().left + $("#wrapper").width() && !$(th).hasClass("tipContainerRight")) {
        				$(th).addClass("tipContainerRight");
        			} else {
        				//$(th).removeClass("tipContainerRight");
        			}
        		}
        		$('.locatorSearchSearchInputx').css({ "width": 209 - $('.locatorSearchSearchInputx').next().width() - 29 });
        	}, this), 300));
        }, function () {
			clearTimeout($.data(this, 'timeout'));
        	$.data(this, 'timeout', setTimeout($.proxy(function () {
        		var p = $(this).parent();
        		$(p).css({ 'position': '', 'zIndex': '' });
        		$('.tipContainer').parent().removeAttr('style');
        		$('.tipContainer').parent().siblings().removeAttr('style');
        		var th = $(this).parent().find('div.tipContainer');
        		if (!$(th).hasClass("intelligence")) {
        			$(th).addClass('dpn');
        		} else {
        			$("body").bind("click", function () {
						$(th).addClass('dpn');
        				$("body").unbind("click");
        			})
        		}
				$('#footerRight .fRate').css({'position':'relative'});
        	}, this), 300));
        })
    }
    $('.tipContainer').hover(function () {
    	clearTimeout($.data(this, 'timeout'));
    	$.data(this, 'timeout', setTimeout($.proxy(function () {
			$('#footerRight .fRate').css({'position':'static'});
    		var p = $(this).parent();
    		$(p).css({ 'position': 'relative', 'zIndex': '5000' });
    		$(this).removeClass("dpn");
    		if ($(this).offset().left + $(this).width() > $("#wrapper").offset().left + $("#wrapper").width() && !$(this).hasClass("tipContainerRight")) {
    			$(this).addClass("tipContainerRight");
    		} else {
    			//$(this).removeClass("tipContainerRight");
    		}

    		$(this).find('span').css({ zoom: 1 });
    	}, this), 300));

    }, function () {
		clearTimeout($.data(this, 'timeout'));
    	$.data(this, 'timeout', setTimeout($.proxy(function () {
    		var p = $(this).parent();
    		$(p).css({ 'position': '', 'zIndex': '' });
    		$('.tipContainer').parent().removeAttr('style');
    		$this = $(this);
    		if (!$this.hasClass("intelligence")) {
    			$this.addClass('dpn');
    		} else {
    			$("body").bind("click", function () {
    				$this.addClass('dpn');
    				$("body").unbind("click");
    			})
    		}
			$('#footerRight .fRate').css({'position':'relative'});
    	}, this), 300));

    });

    $('.tipContainer').click(function () {
    	$(this).addClass("clickednow");
    	setTimeout(function () {
    		$('.clickednow').removeClass("dpn").removeClass("clickednow");
    	}, 10);
    });
}

// run this function when ajax completes
function ajaxloaded() {
    toolTip();
    SortBox();
}


//setting height of sub teasers
function setSubteaserSize() {
	
	var maxH1 = 0, maxH2 = 0, maxHgeneral = 0, $teasers = $(".teaser-type-1, .teaser-type-3"), teaserCount = $teasers.length;
    if (teaserCount > 4) {
        $teasers.each(function (i) {
            if (i <= teaserCount / 2 - 1) {
                if ($(this).height() > maxH1) maxH1 = $(this).height();
            } else {
                if ($(this).height() > maxH2) maxH2 = $(this).height();
            }
        });

        for (var i = 0; i < teaserCount; i++) {
            if (i <= teaserCount / 2 - 1) {
                $($teasers[i]).height(maxH1);
            } else {
                $($teasers[i]).height(maxH2);
            }
        }
    } else {
        $teasers.each(function (i) {
            if ($(this).height() > maxH1) maxH1 = $(this).height();
        });
        $teasers.height(maxH1);
    };
}


//jQuery cookie function, usage ## set --> $.cookie("cookie1", "value"); get --> $.cookie("cookie1");
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

//survey progress bar, page name fixing
function surveyProgressStep() {
    if ($("#surveyProgressStep").length > 0) {
        CurrentStep = parseInt(CurrentStep, 10);
        if (CurrentStep !== "") {
            if (CurrentStep == 0) {
                $.cookie("surveyblueZoneWidth", null);
            };

            blueZone = $(".steps");
            stepName = $(".stepName");
            cookieWidth = $.cookie("surveyblueZoneWidth");
            maxWidth = $(".stepsBar").outerWidth() - ($(".stepsBar .pa").outerWidth() - 22);

            if (blueZone.outerWidth() != $(".stepsBar").outerWidth()) {
                if (stepName.outerWidth() >= maxWidth) {
                    stepName.outerWidth(maxWidth - 40);
                    if (blueZone.outerWidth() < stepName.outerWidth()) {
                        blueZone.outerWidth(maxWidth - 30);
                    };
                } else {
                    if (cookieWidth == null) {
                        if (blueZone.outerWidth() < stepName.outerWidth()) {
                            blueZone.outerWidth(stepName.outerWidth() + 10);
                        };
                    } else {
                        if (cookieWidth > blueZone.outerWidth()) {
                            if ((cookieWidth + 15) < maxWidth) {
                                blueZone.outerWidth(cookieWidth + 15);
                            } else {
                                blueZone.outerWidth(maxWidth - 30);
                            };
                        } else {
                            if (blueZone.outerWidth() < stepName.outerWidth()) {
                                blueZone.outerWidth(stepName.outerWidth() + 10);
                            };
                        };
                    };
                };
            };
            $.cookie("surveyblueZoneWidth", blueZone.outerWidth());
            setTimeout(function () {
                $("#surveyProgressStep").css("visibility", "visible");
            }, 100);
        };
    };
};


function openTabOnLoad(whichtab) {
    var tabs = $('.tabs > li');
    try { tt_Hide(); } catch (ex) { }
    var t = $(whichtab);
    $(tabs).addClass('passive');
    $(t).removeClass('passive');
    var index = $('.tabs > li').index(t);

    if ($('.tabindex > div.tabContainer').eq(index).hasClass('dpn')) {
        $('.tabindex > div.tabContainer').addClass('dpn');
        $('.tabindex > div.tabContainer').eq(index).removeClass('dpn');
    }


}

$(document).ready(function () {


    $("#printbutton").click(function (e) {
        e.preventDefault();
        if ($.browser.msie) {
            document.execCommand('print', false, null);
        } else {
            window.print();
        }
    });

    //Dealer locator search
    $('.tip').live('click', function () {
        return false;
    })
    $('.tipContainer.intelligence .dealer input').focus(function () {
        $(this).val('');
    })
    $('.locatorSearchSearchInput').keyup(function (event) {
        if (event.keyCode == 13) {
            var link = $('.searchString').attr('rel');
            var searchVal = $('.locatorSearchSearchInput').val();
            location.href = link + '&202=' + searchVal;
        }
        return false;
    })
    $('.searchString').live('click', function () {
        if ($('.locatorSearchSearchInput').val() != $('.locatorSearchSearchInput').attr('alt')) {
            var link = $(this).attr('rel');
            var searchVal = $('.locatorSearchSearchInput').val();
            location.href = link + '&202=' + searchVal;
        }
        return false;
    })

    //survey progress bar, page name fixing function runs here
    surveyProgressStep();

    // product sheet magic thumb background heightfix
    $(".headerVisualZoom, .MagicThumb").click(function () {
        setTimeout(function () {
            $("#magicthumb-background").height($("body").height())
        }, 50);
    });

    /*
    Tabs
    */
    var tabListLen = $('.tabs:not(.disable) > li').length;
    var tabs = $('.tabs:not(.disable) > li');
    if (tabListLen) {
        $(tabs).click(function () {
            try { tt_Hide(); } catch (ex) { }
            var t = $(this);
            $(tabs).addClass('passive');
            $(t).removeClass('passive');
            var index = $('.tabs > li').index(t);

            if ($('.tabindex > li').eq(index).hasClass('dpn')) {
                $('.tabindex > li').addClass('dpn');
                $('.tabindex > li').eq(index).removeClass('dpn');
            }

            return false;
        })
    }


    /*
    /Tabs
    */

    /*
    Form mySpan Tags
    */
    var masLinks = $('.mainSpan').length;
    if (masLinks) {
        $('.mainSpan br').wrap('<div class="clear" />');
    }
    var msLinks = $('.mySpan').length;
    if (msLinks) {
        $('.mySpan').each(function () {
            if ($(this).text() == "") {
                $(this).hide();
            }
        })
    }
    /*
    /Form mySpan Tags
    */


    /*
    /Custom Select
    */
    var cSelectL = $('.customSelect').length;
    var cSelect = $('.customSelect');
    if (cSelectL > 0) {
        $('.customSelect > span').each(function () {
            $(this).click(function () {
                if ($('.holder').hasClass('dpn')) {
                    $('.holder').addClass('dpn');
                    $('.holder').removeClass('dpn');
                } else {
                    $('.holder').addClass('dpn');
                }
            })
        })
        $('.holder').each(function () {
            $(this).hover(function () { }, function () {
                $('.holder').addClass('dpn');
            })
        })
    }

    if ($("#dpick2").length || $("#dpick1").length) {
        $(function () {
            $("#dpick2").datepicker({
                showOn: "button",
                buttonImage: "/templates/bosch-resources/images/dpi.png",
                buttonImageOnly: true,
                dateFormat: 'dd/mm/yy',
                beforeShow: function () {
                    $('#dpick2').val($('#e2').val() + '/' + $('#e1').val() + '/' + $('#e3').val());
                    return $('#e2').val() + '/' + $('#e1').val() + '/' + $('#e3').val();
                },
                onSelect: updateLinked2
                //this._get(inst, 'changeMonth')
            });
            $("#dpick1").datepicker({
                showOn: "button",
                buttonImage: "/templates/bosch-resources/images/dpi.png",
                buttonImageOnly: true,
                dateFormat: 'dd/mm/yy',
                beforeShow: function () {
                    $('#dpick1').val($('#d2').val() + '/' + $('#d1').val() + '/' + $('#d3').val());
                    return $('#d2').val() + '/' + $('#d1').val() + '/' + $('#d3').val();
                },
                onSelect: updateLinked1
            });
        });
    }
    function readLinked1() {
        ;
        return {};
    }
    function readLinked2() {
        $('#dpick2').val($('#e2').val() + '/' +
	$('#e1').val() + '/' + $('#e3').val());
        return {};
    }
    function updateLinked1(t_date) {
        var s_mo = t_date.substring(0, 1);
        if (s_mo == '0') {
            $('#d2').val(t_date.substring(1, 2));
        } else {
            $('#d2').val(t_date.substring(0, 2));
        }
        var s_day = t_date.substring(3, 4);
        if (s_day == '0') {
            $('#d1').val(t_date.substring(4, 5));
        } else {
            $('#d1').val(t_date.substring(3, 5));
        }
        $('#d3').val(t_date.substring(6, 10));
    }
    function updateLinked2(t_date) {
        var s_mo = t_date.substring(0, 1);
        if (s_mo == '0') {
            $('#e2').val(t_date.substring(1, 2));
        } else {
            $('#e2').val(t_date.substring(0, 2));
        }
        var s_day = t_date.substring(3, 4);
        if (s_day == '0') {
            $('#e1').val(t_date.substring(4, 5));
        } else {
            $('#e1').val(t_date.substring(3, 5));
        }
        $('#e3').val(t_date.substring(6, 10));
    }
    /*
    /Custom Select  
    */

    //tooltip function, sortbox open/close function, sortbox iefix function
    ajaxloaded();

    // sub teaser set height function runs but not in admin
    if (!IsReallyInAdministration) {
        setSubteaserSize();
    }

    //ie fixes
    iefixes();

    //header three cols heightfix
    if ($(".headerThreeCol").length > 0) {
        $leftCol = $($(".headerThreeCol .headerVisual")[0]);
        $rightCol = $($(".headerThreeCol .headerVisual")[1]);

        if ($leftCol.height() < $rightCol.height()) {
            $leftCol.height($rightCol.height());
        } else if ($leftCol.height() < $rightCol.height()) {
            $rightCol.height($leftCol.height());
        }

    }


    // product sheet first tab fix. 
    if ($(".feature-list").length > 0) {
        // hiding empty ul lists
        $(".feature-list ul").each(function () {
            if ($(this).text() == "") {
                $(this).addClass("dpn");
            }
        });

        //making feature lists click expandible/collapsible
        $(".feature-list > ul > li.expand, .feature-list > ul > li.collapse").live("click", function () {
            if (!$(this).hasClass("collapse")) {
                if ($(this).parent().attr("rel") == undefined) {
                    $(this).parent().attr("rel", $(this).parent().height());

                }

                $(this).addClass("opened-featurelist");
                setTimeout(function () {
                    $(".opened-featurelist").removeClass("expand").addClass("collapse");
                    $(".opened-featurelist").parent().animate({
                        height: 30
                    }, { queue: true, easing: "swing" });
                    $(".opened-featurelist").removeClass("opened-featurelist");
                }, 10)
            } else {

                $(this).removeClass("collapse").addClass("expand");
                $(this).parent().animate({
                    height: $(this).parent().attr("rel")
                }, { queue: true, easing: "swing" });


            };
        }).live("dblclick", function () {
            clearText();
        });


    };

    //product-resultsheet filter fake loading
    $(".specify .filter li input").change(function () {
        $(".specify, .column-2").block();
        /*
        setTimeout(function () {
        $(".specify, .column-2").unblock();
        }, 3000);
        */
    });

    //breadcrumb bg fix
    $(".breadcrumb ul li:last a").css("background", "none");

    // accordion - length control commented because of ajax use
    //if($('.accordeon .header a').length > 0){
    $('.header a').live("click", function () {
        var t = $(this);
        if (t.hasClass("accorNo") && t.hasClass("down")) {
            // do nothing
        } else if (t.hasClass("down")) {
            t.removeClass("down");
            t.parent().parent().next().addClass('dpn');

        } else {
            t.addClass("down");
            t.parent().parent().next().removeClass('dpn');
        }

        /*
        $('.accordeon li .header a').removeClass('down');
        $('.accordeon li .content').addClass('dpn');
        $(t).parent().parent().next().removeClass('dpn');
        $(t).addClass('down');

        */
        return false;
    })
    //}

    // input clear on focus
    if ($("input.focusClear").length > 0) {
        $("input.focusClear").each(function () {
            _$input = $(this);
            _$input.focus(function () {
                if (this.value == this.defaultValue) this.value = "";
            }).blur(function () {
                if (this.value == "") this.value = this.defaultValue;
            });
        })
    };

    //language menu open on mouse over 
    $('#headNav ul.lang').hover(function () {
        $('#mainNav li').css({ 'position': 'static' });
        $('.header-left').css({ 'position': 'static' });
        $(this).addClass('over');
        $("body").css("margin", "0 0 1px 0");
        $("#mainArea").css("zoom", "1");
    }, function () {
        $(this).removeClass('over');
        $('#mainNav li').css({ 'position': 'relative' });
        $('.header-left').css({ 'position': 'relative' });
        $("body").css("margin", "0");
        $("#mainArea").css("zoom", "1");
    });

    $("#mainNav .menuCol ul li").hover(function () {
        $(this).addClass("active");
    }, function () {
        $(this).removeClass("active");
    });

    //main navigation open on mouse over 
    $('div#mainNav > ul:first > li').hover(function () {
        $('#mainNav > ul').addClass('show')
        $(this).addClass('over');
        $("body").css("margin", "0 0 1px 0");
        $("#mainArea").css("zoom", "1");
    }, function () {
        $(this).removeClass('over');
        $('#mainNav > ul').removeClass('show')
        $("body").css("margin", "0");
        $("#mainArea").css("zoom", "1");
    });


    // product carousel buttons
    if ($("#carousel").length > 0) {

        var maxAwidth = 107;
        $("#carouselOverflow .teaser-type-2 h5 a").each(function () {
            if ($(this).outerWidth() > maxAwidth) {
                maxAwidth = $(this).outerWidth();
            } else {
                maxAwidth = maxAwidth;
            }
        })
        $("#carouselOverflow .teaser-type-2").not("#spAdded").css({ "display": "block", "visibility": "visible", "width": maxAwidth })

        var tWidth = 0;
        $("#carouselOverflow .teaser-type-2").each(function () {
            tWidth += $(this).outerWidth();
        });
        if (tWidth < $("#carouselCenter").width()) {
            setTimeout("stopCarousel()", 500);
            $("#carouselLeft, #carouselRight").addClass("disabled");
            $("#carouselOverflow").prepend('<div class="teaser teaser-type-2" id="spAdded" style="width:1px !important;min-width:1px;padding:10px 0 0;background-position:0 0;"></div>')
            $("#carouselLeft").css("border-right", "0");
            $("#carouselRight").css("border-left", "0");
            cWidth = 0;
            $("#carouselOverflow .teaser-type-2").each(function () {
                cWidth = cWidth + $(this).outerWidth();
            });

            leftCenter = $("#carouselCenter").width() / 2 - cWidth / 2;
            $("#carouselOverflow").css("left", leftCenter)
        };

        setTimeout(function () {
            $("#carousel, #carousel div").not(".teaser-type-2, #carouselOverflow").removeAttr("style");
            $("#carousel, #carouselLeft span, #carouselRight span").css("visibility", "visible");
        }, 150);

        $("#carouselRight").bind("click", function (e) {
            e.preventDefault();
            if (!$(this).hasClass("disabled")) {
                if ($("#carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();
                    var copyTeaser = $("#carouselOverflow .teaser:first").clone();
                    var ss = $("#carouselOverflow .teaser:first").outerWidth();
                    $("#carouselOverflow").append(copyTeaser);
                    $("#carouselOverflow").animate({
                        left: "-=" + ss
                    }, { duration: 500, queue: true, complete: function () {
                        $("#carouselOverflow").css({ left: function (index, value) { return parseFloat(value) + ss } });
                        $("#carouselOverflow .teaser:first").remove();
                    }
                    });
                };
            };
        });

        $("#carouselLeft").bind("click", function (e) {
            e.preventDefault();
            if (!$(this).hasClass("disabled")) {
                if ($("#carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();
                    var copyTeaser = $("#carouselOverflow .teaser:last").clone();
                    ss2 = $("#carouselOverflow .teaser:last").outerWidth();
                    $("#carouselOverflow").prepend(copyTeaser).css({ "left": -ss2 });
                    $("#carouselOverflow").animate({
                        left: "+=" + ss2
                    }, { duration: 500, queue: true, complete: function () {
                        $("#carouselOverflow .teaser:last").remove();
                    }
                    });
                };
            }
        });

    }


    //CDB-phase-3 carousel
    if ($("#cdb_carousel").length > 0) {

        alignCDBCarousel();

        $("#cdb_carouselRight").bind("click", function (e) {
            e.preventDefault();
            if ($("#cdb_carouselOverflow").width() + parseInt($("#cdb_carouselOverflow").css("left"), 10) < 616) {
                return false;
            }
            if (!$(this).hasClass("disabled")) {
                if ($("#cdb_carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();
                    //var copyTeaser = $("#cdb_carouselOverflow .teaser:first").clone();
                    $("#cdb_carouselOverflow").animate({
                        left: "-=123"
                    }, { duration: 500, queue: true, complete: function () {
                        if ($("#cdb_carouselOverflow").width() + parseInt($("#cdb_carouselOverflow").css("left"), 10) < 616) {
                            $("#cdb_carouselRight").addClass("disabled");
                        };
                        if (parseInt($("#cdb_carouselOverflow").css("left"), 10) < 0) {
                            $("#cdb_carouselLeft").removeClass("disabled");
                        }

                    }
                    });
                };
            };
        });

        $("#cdb_carouselLeft").bind("click", function (e) {
            e.preventDefault();
            if (parseInt($("#cdb_carouselOverflow").css("left"), 10) >= 0) {
                return false;
            }
            if (!$(this).hasClass("disabled")) {
                if ($("#cdb_carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();
                    //var copyTeaser = $("#cdb_carouselOverflow .teaser:last").clone();
                    //$("#cdb_carouselOverflow").prepend(copyTeaser).css({ "left": "-126px" });


                    $("#cdb_carouselOverflow").animate({
                        left: "+=123"
                    }, { duration: 500, queue: true, complete: function () {

                        if ($("#cdb_carouselOverflow").width() + parseInt($("#cdb_carouselOverflow").css("left"), 10) > 616) {
                            $("#cdb_carouselRight").removeClass("disabled");
                        };
                        if (parseInt($("#cdb_carouselOverflow").css("left"), 10) == 0) {
                            $("#cdb_carouselLeft").addClass("disabled");
                        }

                    }
                    });
                };
            }
        });


        $("#cdb_carouselOverflow .teaser-type-2 h5, #cdb_carouselOverflow .teaser-type-2 .teaserImg").bind("click", function (e) {
            e.preventDefault();
            $this = $(this);
            divList = $(".product-detail-list > div.product-detail");
            if ($this.hasClass("addproduct")) {
                location.href = $this.find("a").attr("href");
            } else {
                prodID = $this.parent().attr("rel");

                divList.hide();

                $(".product-detail-list > div.product-detail[rel='" + prodID + "']").show();
                $(".CdbSubFreeContents").show();
                $(".CdbSubFreeContents .header h5 a").removeClass("down");
                $(".CdbSubFreeContents ul.main .content").addClass("dpn");

                $("#cdb_carouselOverflow .teaser-type-2").removeClass("selected").removeClass("selectedBefore");
                $this.parent().addClass("selected");
                $this.parent().prev().addClass("selectedBefore");

            }
        });


        $("#cdb_carouselOverflow .teaser-type-2. .teaser-remove").bind("click", function (e) {
            e.preventDefault();
            ans = confirm(cdb_question);
            if (ans) {
                removeItem = $(this);
                prodID = removeItem.parent().attr("rel");
                index = $(" #cdb_carouselOverflow > div").index(removeItem.parent());
                $.ajax({
                    url: location.href,
                    type: 'Post',
                    data: { prodId: prodID },
                    beforeSend: function () {
                        $(".cdbForm").block();
                    },
                    success: function (result) {
                        if (result == "OK") {
                            removeItem.parent().animate({
                                width: 0,
                                paddingRight: 0,
                                paddingLeft: 0
                            }, { duration: 250, queue: true, complete: function () {
                                removeItem.parent().remove();
                                //$(".product-detail-list div[rel=" + prodID + "]").remove();
                                $(".product-detail-list > div").eq(index).remove();
                                alignCDBCarousel();
                            }
                            });
                        } else {
                            alert(cdb_errormg);
                        }
                        $(".cdbForm").unblock();
                    },
                    error: function () {
                        alert(cdb_errormg);
                        $(".cdbForm").unblock();
                    }
                });



            }
        });



    }

    //FAQ carousel begin
    if ($("#faq_carousel").length > 0) {

        alignFAQCarousel();

        $("#faq_carouselRight").bind("click", function (e) {
            e.preventDefault();
            if ($("#faq_carouselOverflow").width() + parseInt($("#faq_carouselOverflow").css("left"), 10) < 616) {
                return false;
            }
            if (!$(this).hasClass("disabled")) {
                if ($("#faq_carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();

                    $("#faq_carouselOverflow").animate({
                        left: "-=123"
                    }, { duration: 500, queue: true, complete: function () {
                        if ($("#faq_carouselOverflow").width() + parseInt($("#faq_carouselOverflow").css("left"), 10) < 616) {
                            $("#faq_carouselRight").addClass("disabled");
                        };
                        if (parseInt($("#faq_carouselOverflow").css("left"), 10) < 0) {
                            $("#faq_carouselLeft").removeClass("disabled");
                        }

                    }
                    });
                };
            };
        });

        $("#faq_carouselLeft").bind("click", function (e) {
            e.preventDefault();
            if (parseInt($("#faq_carouselOverflow").css("left"), 10) >= 0) {
                return false;
            }
            if (!$(this).hasClass("disabled")) {
                if ($("#faq_carouselOverflow").queue("fx").length < 1) {
                    $(this).blur();


                    $("#faq_carouselOverflow").animate({
                        left: "+=123"
                    }, { duration: 500, queue: true, complete: function () {

                        if ($("#faq_carouselOverflow").width() + parseInt($("#faq_carouselOverflow").css("left"), 10) > 616) {
                            $("#faq_carouselRight").removeClass("disabled");
                        };
                        if (parseInt($("#faq_carouselOverflow").css("left"), 10) == 0) {
                            $("#faq_carouselLeft").addClass("disabled");
                        }

                    }
                    });
                };
            }
        });


        $("#faq_carouselOverflow .teaser-type-2 h5, #faq_carouselOverflow .teaser-type-2 .teaserImg").bind("click", function (e) {
            e.preventDefault();
            $this = $(this);
            divListFaq = $(".faqAccList > div.faqAccItem");
            faqID = $this.parent().attr("rel");

            divListFaq.hide();
            $(".faqAccList > div.faqAccItem[rel='" + faqID + "']").show();
            //            $(".CdbSubFreeContents").show();
            //            $(".CdbSubFreeContents .header h5 a").removeClass("down");
            //            $(".CdbSubFreeContents ul.main .content").addClass("dpn");

            $("#faq_carouselOverflow .teaser-type-2").removeClass("selected").removeClass("selectedBefore");
            $this.parent().addClass("selected");
            $this.parent().prev().addClass("selectedBefore");
        });



    }

    //FAQ carousel end

    // Ticker buttons
    $(".fadeTicker .column-2 .teaser").each(function (i) {
        $(this).attr("rel", i).css({
            "opacity": "0",
            "display": "none"
        });
    });

    $(".fadeTicker .column-2 .teaser:first").animate({
        opacity: 1
    }, { duration: 500, queue: true, complete: function () {
        $(".fadeTicker .column-2 .teaser:first").css("display", "block").addClass("active");
    }
    });

    $("#tickerRight").bind("click", function (e) {
        e.preventDefault();
        $(this).blur();
        _$visibleTicker = $(".fadeTicker .column-2 .teaser[class~=active]");
        nextTicker = parseInt(_$visibleTicker.attr("rel"), 10) + 1;
        //_$visibleTicker.animate({ opacity: 0 }, 750).css("display", "none").removeClass("active");

        _$visibleTicker.animate({
            opacity: 0
        }, { duration: 400, queue: true, complete: function () {
            _$visibleTicker.css("display", "none").removeClass("active");
        }
        });

        _$nextTicker = $(".fadeTicker .column-2 .teaser[rel=" + nextTicker + "]");
        if (_$nextTicker.length == 1) {
            _$nextTicker.animate({
                opacity: 1
            }, { duration: 400, queue: true, complete: function () {
                _$nextTicker.css("display", "block").addClass("active");
            }
            });

        } else {
            $(".fadeTicker .column-2 .teaser:first").animate({
                opacity: 1
            }, { duration: 400, queue: true, complete: function () {
                $(".fadeTicker .column-2 .teaser:first").css("display", "block").addClass("active");
            }
            });
        };

    });

    $("#tickerLeft").bind("click", function (e) {
        e.preventDefault();
        $(this).blur();
        _$visibleTicker = $(".fadeTicker .column-2 .teaser[class~=active]");
        prevTicker = parseInt(_$visibleTicker.attr("rel"), 10) - 1;
        _$visibleTicker.animate({
            opacity: 0
        }, { duration: 400, queue: true, complete: function () {
            _$visibleTicker.css("display", "none").removeClass("active");
        }
        });
        _$prevticker = $(".fadeTicker .column-2 .teaser[rel=" + prevTicker + "]");
        if (_$prevticker.length == 1) {
            _$prevticker.animate({
                opacity: 1
            }, { duration: 400, queue: true, complete: function () {
                _$prevticker.css("display", "block").addClass("active");
            }
            });
        } else {
            $(".fadeTicker .column-2 .teaser:last").animate({
                opacity: 1
            }, { duration: 400, queue: true, complete: function () {
                $(".fadeTicker .column-2 .teaser:last").css("display", "block").addClass("active");
            }
            });
        };
    });

    // product sheet tab teaser fix
    if ($(".tab-teaser-1").length > 0) {
        $(".tab-teaser-1 h5").each(function () {
            if ($(this).text() == "" || $(this).find("a").text() == "") {
                $(this).css("display", "none");
            };
        });
    }

    //footer scrollToTop link
    $(".scrollToTop").bind("click", function (e) {
        e.preventDefault();
        $('html, body').animate({ scrollTop: 0 }, 250);
    });

    // animating menu title hover on navigation image hover
    $(".navImage").hover(function () {
        $($(this).next()[0]).children("li:first").addClass('active');
    }, function () {
        $($(this).next()[0]).children("li:first").removeClass('active');
    });

    // mainNavigation Width fix
    $(".shadow").each(function () {
        var shadowWidth = 0, colCount = 0, $wr = $("#wrapper"), $this = $(this);
        colCount = $(this).find(".menuCol").length;
        if (colCount > 3) {
            colCount = 3;
        } else {
            colCount--;
        }
        shadowWidth = 264 + (232 * colCount);
        $this.css("width", shadowWidth);

        menuleft = $this.offset().left - $wr.offset().left;
        leftDiff = ($this.width() + menuleft) - $wr.width();
        wright = $wr.offset().left + $wr.width();
        tright = $this.offset().left + $this.width();

        if (tright - wright > 0) {
            finalLeft = parseInt($this.css("left"), 10) - ((tright - wright) + 22);
            $this.css("left", finalLeft);
        };

        setTimeout(function () {
            $(".lang1 .shadowTop").width($(".lang1 .shadow").width() - $(".lang1").width() - 37);
        }, 50);
    });

    // store menu position calculation
    if ($(".nectarstoreIntegration").length > 0 && $(".nectarstoreIntegrationUL").length > 0) {
        $(".nectarstoreIntegration").css("left", -($(".nectarstoreIntegrationUL").offset().left - $("#wrapper").offset().left - 6))
    }

    // { font-size adjust
    /*
    $(".fFontSize .fSmall").click(function () {
    if (!$(this).hasClass("active")) {
    $.blockUI();
    $(".fFontSize span").removeClass("active");
    $(this).addClass("active");
    $("*").css({ 'font-size': "" });
    setTimeout(function () {
    $("*").each(function () {
    var textsize = $(this).css("font-size");
    var textunit = textsize.slice(-2);
    textsize = parseFloat(textsize, 10);
    textsize--;
    $(this).animate({ 'font-size': textsize + textunit });
    });
    setTimeout(function () {
    $.unblockUI();
    }, 1000);
    }, 1000);
    } else {
    return false;
    }
    });

    $(".fFontSize .fMedium").click(function () {
    if (!$(this).hasClass("active")) {
    $.blockUI();
    $(".fFontSize span").removeClass("active");
    $(this).addClass("active");
    setTimeout(function () {
    $("*").each(function () {
    $(this).css({ 'font-size': "" });
    });
    setTimeout(function () {
    $.unblockUI();
    }, 1000);
    }, 1000);
    } else {
    return false;
    }
    });

    $(".fFontSize .fLarge").click(function () {
    if (!$(this).hasClass("active")) {
    $.blockUI();
    $(".fFontSize span").removeClass("active");
    $(this).addClass("active");
    $("*").css({ 'font-size': "" });
    setTimeout(function () {
    $("*").each(function () {
    var textsize = $(this).css("font-size");
    var textunit = textsize.slice(-2);
    textsize = parseFloat(textsize, 10);
    textsize++;
    $(this).animate({ 'font-size': textsize + textunit });
    });
    setTimeout(function () {
    $.unblockUI();
    }, 1000);
    }, 1000);
    } else {
    return false;
    }
    });
    */


    $("#footer .addthis_button img").removeAttr("alt");

    $(".fRecommend").mousedown(function (e) {
        e.preventDefault();
        $(".fRecommend").trigger("click");
    });


});

$(window).load(function () {

});

$(window).resize(function () {

});

