function flashWrite(flashfile,x,y,flashvar) {
	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ x +"' height='"+ y +"'>");
	document.write("<param name='movie' value='"+ flashfile +"' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='flashvars' value='"+ flashvar +"' />");
	document.write("<param name='wmode' value='transparent' />");
	document.write("<embed src='"+ flashfile +"' wmode='transparent' ");
	document.write("flashvars='"+ flashvar +"'  ");
	document.write("quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ x +"' height='"+ y +"'></embed>");
	document.write("</object>");
}

function printYear() {
	var today = new Date();
	document.write(today.getFullYear());
}

function writeEmail(email) {
	document.write('<a href="mailto:'+email+'">'+email+'</a>');
}

function changeTextSize(textSize) {
   document.body.className = 'site ' + textSize;
    // $('body').addClass(textSize);
	return false;
}

function printPage() {
	window.print();
	return false;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

$(document).ready(function() {
    if ($('div.lightbox').length > 0) {
        $('div.lightbox a').lightBox({
            imageLoading: '/cms/outertemplates/images/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/cms/outertemplates/images/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/cms/outertemplates/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/cms/outertemplates/images/lightbox/lightbox-btn-next.gif'
        });
    }
    $(':first-child').addClass('first');
    $(':last-child').addClass('last');
    $('a[rel=newWindow]').attr('target', '_blank');

    $('img.backgroundimage').maxImage({
        isBackground: true,
        slideShow: false,
        verticalAlign: 'top',
        slideShowTitle: false,
        maxFollows: 'height',
        position: 'fixed'
    });

    $('#infoBar ul').adidoCarousel({ buttons: false, mode: 'fade' });
    $('#carousel ul').adidoCarousel({ horizontal: false, hoverPause: true, imgContainer: '#carouselImg', imgLarge: true });
    $('.quoteMask ul').adidoCarousel({ mode: 'fade' });
    $('#tabNews ul').adidoCarousel({ horizontal: false });

    $('a.lnkView').bigTarget({ clickZone: 'div:eq(3)' });
    $('a.prodLink').bigTarget({ clickZone: 'div:eq(2)' });

    $('a.lnkShowBasket').click(function(e) {
        e.preventDefault();
        $('div.miniBasketDrop').slideToggle();
    });

    var h = 0;

    $('.quoteMask').find('li').each(function() {
        var s = $(this).height();
        if (s > h) {
            h = s;
        }
    }).end().height(h);


    var h = 0;
    $('.homeBox').each(function() {
        var i = $(this).height();
        if (i > h) {
            h = i;
        }
    }).height(h);

    $('#headerLinks a.lnkHeader').click(function(e) {
        e.preventDefault();
        var t = $(this).attr('href');
        if ($(t).hasClass('headerLinkOpen')) {
            $(t).removeClass('headerLinkOpen').slideUp();
        } else {
            $(t).siblings('.headerLinkOpen').removeClass('headerLinkOpen').hide().end().addClass('headerLinkOpen').slideDown();

        }
    });

    $('.rightColTabs ul').addClass('tabOne').find('li:eq(0) a').addClass('tabActive');
    $('div.tabContent').not(':eq(0)').hide();

    $("#pageflip").hover(function() { //On hover...
        $("#pageflip, #pageflip img , .msg_block").stop()
		.animate({ //Animate and expand the image and the msg_block (Width + height)
		    width: '321px',
		    height: '300px'
		}, 500);
    }, function() {
        $("#pageflip").stop().animate({
            width: '50px',
            height: '50px'
        });
        $("#pageflip img").stop() //On hover out, go back to original size 50x52
		.animate({
		    width: '50px',
		    height: '52px'
		}, 220);
        $(".msg_block").stop() //On hover out, go back to original size 50x50
		.animate({
		    width: '48px',
		    height: '50px'
		}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
    });

    $('#pageFlip').hover(function() {
        $(this).stop().animate({ height: '300px', width: '321px' });
        $('img.pageFlip-mask').stop().animate({ height: '300px', width: '321px' });
    }, function() {
        $(this).stop().animate({ height: '50px', width: '50px' });
        $('img.pageFlip-mask').stop().animate({ height: '50px', width: '50px' });
    });


    $('.rightColTabs ul li a').click(function(e) {
        e.preventDefault();
        var r = $(this).attr('rel');
        var t = $(this).attr('href');
        if ($(this).hasClass('tabActive')) {
            $(this).size();
        } else {
            $('.rightColTabs ul li a.tabActive').removeClass('tabActive');
            $(this).addClass('tabActive');
            $(this).parents('ul').removeClass().addClass(r);
            $(t).show().siblings().hide();
        }
    });

    $('.listingImg').corners();
    $('.listingInfo').corners();


    $('ul.productTabs').children('li').each(function() {
        var a = $(this).index();
        $(this).children('a').click(function(e) {
            e.preventDefault();
            $(this).parent('li').addClass('activeTab').siblings().removeClass('activeTab');
            $('div.productTabContent:eq(' + a + ')').show().siblings('div').hide();
        });
    }).end().children('li:eq(0)').addClass('activeTab').end().siblings('div:eq(0)').show().siblings('div').hide();

    $('#productImageThumbs a').each(function() {
        $(this).click(function(e) {
            e.preventDefault();
            var s = $(this).attr('href');
            $('#productImage img').attr('src', s);
            $('#productImage a').attr('href', s);
        });
    });

    $('a.lightboxLink').lightBox({
        imageBtnClose: '/cms/outertemplates/images/lightbox/lightbox-btn-close.gif',
        imageLoading: '/cms/outertemplates/images/lightbox/lightbox-ico-loading.gif',
        imageBtnPrev: '/cms/outertemplates/images/lightbox/lightbox-btn-prev.gif',
        imageBtnNext: '/cms/outertemplates/images/lightbox/lightbox-btn-next.gif',
        imageBlank: '/cms/outertemplates/images/lightbox/lightbox-blank.gif'
    });

    if (IE6) {
        $('img.backgroundimage').hide();
    }
    $('.ddlReason').each(function() {
        var v = $(this).val();
        if (v == 'Other') {
            $('.txbOther').show().focus();
        } else {
            $('.txbOther').hide();
        }
    }).change(function() {
        var v = $(this).val();
        if (v == 'Other') {
            $('.txbOther').show().focus();
        } else {
            $('.txbOther').hide();
        }
    });

    $('.lnkHelp').click(function(e) {
        e.preventDefault();
        $('.popupHelp').fadeIn();
    });
    $('.lnkHelpClose').click(function(e) {
        e.preventDefault();
        $('.popupHelp').fadeOut();
    });

});
