	var $j = jQuery.noConflict();
	$j(document).ready(function () {

	    //set default ease
	    $j.easing.def = "easeInSine";

	    //Site Width Adjustment
	    function siteWidth() {
	        var windowWidth = $j(window).width();
	        if (windowWidth < 1330) {
	            $j('.container').addClass('short');
	        } else {
	            $j('.container').removeClass('short');
	        }
	        footerLinks();

	    }
	    $j(window).resize(function () {
	        siteWidth();
	    });
	    siteWidth();

	    //minheight for content
	    if ($j('.centerColumn .content').length) {
	    	if(($j('.rightColumn').height() < $j('.leftColumn').height())) {
	        	$j('.centerColumn .content').css('min-height', ($j('.leftColumn').height()));
	        } else {
	        	$j('.centerColumn .content').css('min-height', ($j('.rightColumn').height() - 62)); // 62 is padding
	        }
	    }

	    //Set footer width
	    function footerLinks() {
	        var footerLinksWidth = $j('.footerLinks .container').width()
	        $j('.footerLinks li').css({ width: (footerLinksWidth / 9 - 1) })
	        //alert(footerLinksWidth)
	    }

	    $j('.locateLeft, .inputPostcode, .inputAjaxSearch').inputClearer();

	    //ie fixer
	    if ($j.browser.msie && $j.browser.version <= "7.99") {
	        var zIndexNumber = 1000;
	        $j('.dropdown div').each(function () {
	            $j(this).css('zIndex', zIndexNumber);
	            zIndexNumber -= 10;
	        });
	    }

	    //Set inital BG for Ribbon
	    var windowWidth = $j(window).width();
	    $j('.wellBg').css({ backgroundPosition: (windowWidth / 2.5) + 'px 3px' }, 1200)
	    if ( $j('.container').hasClass('short') )
	    	$j('.wellBg').css({ backgroundPosition: (windowWidth / 6) + 'px 3px' }, 1200)
	    //Ribbon Switch
	    $j('.switch1').click(function () {
	        var windowWidth = $j(window).width();
	        $j('.frame1').stop().animate({ left: -1330, opacity: 0 }, 1000, function () {
	            $j('.frame2').css('display', 'block').stop().animate({ left: 0, opacity: 1 }, 1000);
	            $j('.frame1').css({ display: 'none', left: 1330 });
	            $j('.wellBg2').css({ backgroundPosition: windowWidth + 'px 3px' }).animate({ backgroundPosition: (windowWidth / 2.5) + 'px 3px' }, 1000)
	        })
	        $j('.wellBg').animate({ backgroundPosition: '-' + windowWidth + 'px 3px' }, 1200);
	        $j('.slideFrame').animate({ opacity: 0, left: '-' + windowWidth }, 1200, function () {
	            $j('.slideFrame').animate({ height: 0 }, 400)
	            $j('.slideFrame2').animate({ height: ($j('.slideFrame2 .homeFrame').height() + 20) }, 400, function () {
	                $j('.slideFrame2').animate({ opacity: 1 }, 500)
	                $j('.slideFrame').css({ left: 0 })
	            });
	        });
	        return false
	    });
	    $j('.switch2').click(function () {
	        $j('.frame2').stop().animate({ left: -1330, opacity: 0, backgroundPosition: '-400px 3px' }, 1000, function () {
	            $j('.frame1').css('display', 'block').stop().animate({ left: 0, opacity: 1 }, 1000);
	            $j('.frame2').css({ display: 'none', left: 1330 });
	            $j('.wellBg').css({ backgroundPosition: windowWidth + 'px 3px' }).animate({ backgroundPosition: (windowWidth / 2.5) + 'px 3px' }, 1000)
	        })
	        $j('.wellBg2').animate({ backgroundPosition: '-' + windowWidth + 'px 3px' }, 1200);
	        $j('.slideFrame2').animate({ opacity: 0, left: '-' + windowWidth }, 1200, function () {
	            $j('.slideFrame2').animate({ height: 0 }, 300)
	            $j('.slideFrame').animate({ height: ($j('.slideFrame .homeFrame').height() + 20) }, 300, function () {
	                $j('.slideFrame').animate({ opacity: 1 }, 200)
	                $j('.slideFrame2').css({ left: 0 })
	            });
	        });
	        return false
	    });

	    //Call Now Anim
	    $j('.callNow').toggle(function () {

	        trackConversion();

	        if ($j(this).hasClass('nz')) {
	            $j(this).animate({ paddingRight: 94 }, 100)
	        } else {
	            $j(this).animate({ paddingRight: 74 }, 100)
	        }
	        //record the hit.
	        jQuery.ajax({
	            type: "POST",
	            url: "/Resources/ws-common.aspx",
	            data: "{ 'view':'callnow', 'scpk':'" + $j(this).attr('rel') + "', 'ref':'" + window.location.href + "' }",
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            cacheResponse: true,
	            beforeSend: function (xhr) {
	                xhr.setRequestHeader("DNN-Service", "true");
	                xhr.setRequestHeader("DNN-Service-Method", "callnow");
	            },
	            success: function (msg) {
	            },
	            error: function (xhr, msg, e) {
	                alert(msg + '\n' + xhr.status + ': ' + xhr.statusText);
	            }

	        });
	    }, function () {
	        $j(this).animate({ paddingRight: 10 }, 100)
	    });

	    $j('.scCallNow').toggle(function () {
	        $j(this).animate({ width: ($j('span', this).width() + 150) }, 100)

	        //record the hit.
	        jQuery.ajax({
	            type: "POST",
	            url: "/Resources/ws-common.aspx",
	            data: "{ 'view':'callnow', 'scpk':'" + $j(this).attr('rel') + "', 'ref':'" + window.location.href + "' }",
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            cacheResponse: true,
	            beforeSend: function (xhr) {
	                xhr.setRequestHeader("DNN-Service", "true");
	                xhr.setRequestHeader("DNN-Service-Method", "callnow");
	            },
	            success: function (msg) {
	            },
	            error: function (xhr, msg, e) {
	                alert(msg + '\n' + xhr.status + ': ' + xhr.statusText);
	            }

	        });

	        return false
	    }, function () {
	        $j(this).animate({ width: 100 }, 100)
	        return false
	    })
	    
        $j('.altCallNow').live('click', function () {
            $j(this).animate({ width: ($j('span', this).width() + 150) }, 100)
            return false
        });
        
	    //iPad detection so that dropdowns work
	    var isiPad = navigator.userAgent.match(/iPad/i) != null;
	    if (isiPad) {
	        $j('.nav li .last').click(function () {
	            window.location = "/ContactUs.aspx";
	        });
	        $j('.nav li > a').click(function () {
	            if (!($j(this).hasClass('last') || $j(this).hasClass('home'))) {
	            	$j(this).siblings().removeClass('iPadOn')
	            	$j(this).addClass('iPadOn')
	            	return false
	            }
	        });
	        $j('.whiteOut').click(function () {
	            $j(this).stop().animate({ opacity: 0 }, 400, function () {
	                $j('.whiteOut').css({ width: 0, height: 0 })
	            })
	        });


	    }

	    //nav
	    if ($j.browser.msie && $j.browser.version <= "8.99") {
	        $j('.nav > li').hover(function () {
	            //get nav arrow position
	            var arrowOffset = $j(this).position()
	            $j('.arrow').css({ left: (arrowOffset.left + 37) })

	            //make the magic happen

	            if (!($j('.home', this).length || $j(this).hasClass('search'))) {
	                //whiteout
	                if ($j.browser.msie && $j.browser.version >= "8.0") {
	                    $j('.whiteOut').css({ width: ($j('body').width()), height: ($j('body').height()) }).stop().fadeIn(300);
	                }

					var dropHeight = $j('.dropdown .text', this).height();
	                //plus 100 is for the padding
	                $j('.dropdown', this).stop().animate({ height: (dropHeight + 100) }, 300, function () {

	                })
	            }
	        }, function () {
	            $j('.dropdown', this).stop().delay(100).animate({ height: 0 }, 300, function () {

	            })


	            $j('.whiteOut').stop().fadeOut(400, function () {
	                $j('.whiteOut').css({ width: 0, height: 0 })
	            });
	        });
	    } else {
	        //set opacity for non ie users
	        $j('.nav li .dropdown').css({ opacity: 0 });

	        $j('.nav > li').hover(function () {
	            //get nav arrow position
	            var arrowOffset = $j(this).position()
	            $j('.arrow').css({ left: (arrowOffset.left + 37) })
	            $j('.short .arrow').css({ left: (arrowOffset.left + 250) })

	            //make the magic happen
	            //calculate dropdown height
	            var dropHeight = $j('.dropdown .text', this).height();
	            $j('.nav > li a').removeClass('hover')
	            $j(this).addClass('hover')
	            $j('.dropdown .shine').css({ top: -556 });

	            if (!($j('.home', this).length || $j(this).hasClass('search'))) {
	                //whiteout
	                $j('.whiteOut').css({ width: ($j('body').width()), height: ($j('body').height()) }).stop().animate({ opacity: 1 }, 200);

	                $j('.dropdown', this).css({ height: (dropHeight + 100), zIndex: 10 }).stop().animate({ opacity: 1 }, 200, function () {
	                    $j('.dropdown .shine').animate({ top: (dropHeight + 100) }, 800);
	                })

	            }
	        }, function () {

	            if ($j.browser.msie && $j.browser.version <= "8.0") {
	                $j('.whiteOut').stop().fadeOut(400, function () {
	                    $j('.whiteOut').css({ width: 0, height: 0 })
	                });
	            } else {
	                $j('.whiteOut').stop().animate({ opacity: 0 }, 400, function () {
	                    $j('.whiteOut').css({ width: 0, height: 0 })
	                });
	            }

	            if ($j.browser.msie && $j.browser.version <= "8.0") {
	                $j('.dropdown', this).css({ zIndex: 5 }).fadeOut(400, function () {
	                    $j('.dropdown .shine').css({ top: -556 });
	                    $j(this).css({ height: 0 })
	                })
	            } else {
	                $j('.dropdown', this).css({ zIndex: 5 }).animate({ opacity: 0 }, 400, function () {
	                    $j('.dropdown .shine').css({ top: -556 });
	                    $j(this).css({ height: 0 })
	                })
	            }

	            $j('.nav li').removeClass('hover')
	        });
	    }

	    //menu anim

	    $j('.menu > li').hover(function () {
	        if (!($j(this).hasClass('on'))) {
	            $j('a', this).stop().animate({ backgroundPosition: '3px 0px', color: '#000000' }, { easing: 'easeOutQuart', duration: 500 });
	            $j('a span', this).stop().animate({ backgroundPosition: '0px bottom', color: '#000000' }, { easing: 'easeOutQuart', duration: 500 });
	        }
	    }, function () {
	        if (!($j(this).hasClass('on'))) {
	            $j('a', this).stop().animate({ backgroundPosition: '165px 0px', color: '#959595' }, { easing: 'easeOutQuart', duration: 500 });
	            $j('span', this).stop().animate({ backgroundPosition: '165px bottom', color: '#959595' }, { easing: 'easeOutQuart', duration: 500 });
	        }
	    });

	    $j('.subMenu > li').hover(function () {
	        if (!($j('a', this).hasClass('on'))) {
	            $j('a', this).stop().animate({ color: '#000000' }, { easing: 'easeOutQuart', duration: 500 });
	        }
	    }, function () {
	        if (!($j('a', this).hasClass('on'))) {
	            $j('a', this).stop().animate({ color: '#C7C7C7' }, { easing: 'easeOutQuart', duration: 500 });
	        }
	    });
	    $j('.subMenu > li a:last').addClass('last');


	    $j('.scNav li').hover(function () {
	        var liHeight = 0
	        $j('li', this).each(function () {
	            (liHeight += $(this).height());
	        })
	        liHeight = (liHeight + 10)
	        $j('ul', this).stop().animate({ height: liHeight }, { easing: 'easeOutQuart', duration: 400 });
	        if (!($j('a', this).hasClass('on'))) {
	            if ($j('a', this).hasClass('menuDrop')) {
	                $j('> a', this).stop().animate({ backgroundPosition: '10px 48px' }, { easing: 'easeOutQuart', duration: 400 });
	            } else {
	                $j('a', this).stop().animate({ backgroundPosition: '0px 44px' }, { easing: 'easeOutQuart', duration: 400 });
	            }
	            $j('span', this).stop().animate({ color: '#e21718' }, { easing: 'easeOutQuart', duration: 400 });
	        }
	    }, function () {
	        $j('ul', this).stop().animate({ height: 0 }, { easing: 'easeOutQuart', duration: 400 });
	        if (!($j('a', this).hasClass('on'))) {
	            if ($j('a', this).hasClass('menuDrop')) {
	                $j('> a', this).stop().animate({ backgroundPosition: '10px 59px' }, { easing: 'easeOutQuart', duration: 400 });
	            } else {
	                $j('a', this).stop().animate({ backgroundPosition: '0px 59px' }, { easing: 'easeOutQuart', duration: 400 });
	            }
	            $j('span', this).stop().animate({ color: '#ffffff' }, { easing: 'easeOutQuart', duration: 400 });
	        }
	    });

	    //width for servicing industry area
	    if ($j('.scBody .industries').length) {
	        var aWidth = 0
	        $j('.scBody .industries a').each(function () {
	            (aWidth += $(this).width() + 20);
	            $j('.scBody .top2').width(432 - aWidth)
	        })
	    }

	    //Tab system for product categories
	    $j('.productSelect a').hover(function () {
	        $j(this).stop().animate({ backgroundPosition: "right 19px" }, 200);
	        $j('span', this).stop().animate({ backgroundPosition: "left 19px" }, 200);
	    }, function () {
	        $j(this).stop().animate({ backgroundPosition: "right 39px" }, 200);
	        $j('span', this).stop().animate({ backgroundPosition: "left 39px" }, 200);
	    });

	    //set init
	    if ($j('.productSelect').length) {
	        $j('#productSelect-b1').carouFredSel({
	            width: '767',
	            height: 'auto',
	            prev: '.prev',
	            next: '.next',
	            pagination: ".pager",
	            auto: false,
	            circular: true,
	            scroll: 2
	        });
	        //do fade ins/outs
	        $j('.centerColumn .productSelect a').click(function () {
	            var productCat = $j(this).attr('href');
	            $j('.centerColumn .overview').stop().animate({ opacity: 0 }, 400, function () {
	                $j('.centerColumn .overview').css({ height: 0 })
	                $j(productCat).css({ height: 111 }).stop().animate({ opacity: 1 }, 400)
	                $j('.centerColumn .caroufredsel_wrapper').css({ height: 0 })
	                $j(productCat).parent().css({ height: 162 })
	            })
	            $j('.centerColumn .productSelect a').removeClass('on');
	            $j(this).addClass('on');


	            $j(function () {
	                $j(productCat).carouFredSel({
	                    width: '767',
	                    height: 'auto',
	                    prev: '.prev',
	                    next: '.next',
	                    pagination: ".pager",
	                    auto: false,
	                    circular: true,
	                    scroll: 2
	                });
	            });



	            if ($j('.centerColumn .viewport .pager').hasClass('hidden')) {
	                $j('.centerColumn .viewport').stop().animate({ height: 159 }, 400)
	            } else {
	                $j('.centerColumn .viewport').stop().animate({ height: 190 }, 400)
	            }

	            $j('.centerColumn .productList').stop().animate({ height: 0, opacity: 0 });

	            return false
	        });

	        $j('.closeProductList').click(function() {
				$j('.productList').stop().animate({ height: 0, opacity: 0 });
		    });

	        $j('.overview a').click(function () {

	        	$j(window).scrollTo('.productScroll', 400, {axis:'y'}); 

	            var thisItem = $j(this).text().replaceAll(" ", "");
	            var thisOffset = $j(this).parent().offset();

	            $j('.productList').stop().animate({ height: 0, opacity: 0 }, function () {
	                $j('#' + thisItem).stop().animate({ height: ($j('#' + thisItem + ' .text').height() + 70), opacity: 1 }, 500, function () {
	                    $j('#' + thisItem + ' .arrow').stop().animate({ left: (thisOffset.left - 464) }, 400);
	                });
	            });



	            return false
	        });
	    }

	    var marketCount = 0
		$j('.marketBox a').each(function() {
			$j(this).attr('id', marketCount)
			marketCount += 1;
		})
	    $j('.marketBox a').hover(function() {
	    	if ($j(this).hasClass('Agriculture'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -0px' })
			if ($j(this).hasClass('Automotive'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -93px' })
	    	if ($j(this).hasClass('Construction'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -186px' })
	    	if ($j(this).hasClass('Earthmoving'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -279px' })
	    	if ($j(this).hasClass('Forestry'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -372px' })
	    	if ($j(this).hasClass('Manufacturing'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -465px' })
	    	if ($j(this).hasClass('Marine'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -558px' })
	    	if ($j(this).hasClass('Mining'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -651px' })
	    	if ($j(this).hasClass('Transport'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -744px' })
	    	if ($j(this).hasClass('AllMarkets'))
	    		$j('.marketImg').stop().animate({backgroundPosition: '0px -837px' })



	    })

	   



	});

