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;
	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;
}

function hideOverlay(pu) {
    $('.bgOverlay').fadeOut(500, function() { $(this).remove(); });

    pu.fadeOut(500);
}
function showOverlay(pu) {
    var $bg = $('<div class="bgOverlay"></div>');
    $bg.hide().click(function() {
        hideOverlay(pu);
    });
    var dh = $(document).height();
    var dw = $(document).width();
    $bg.height(dh).width(dw);
    $bg.appendTo('body > form').fadeTo(500, 0.6);

    pu.fadeIn(500);
}

$(document).ready(function() {
    if ($('div.lightbox').length > 0) {
        $('div.lightbox a').lightBox({
            imageLoading: '/system/assets/images/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/system/assets/images/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/system/assets/images/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/system/assets/images/lightbox/lightbox-btn-next.gif'
        });
    }

    $('div.catPopup').appendTo('body > form:first-child');
    $('div.productPopup').appendTo('body > form:first-child');

    $('#homeCarouselCont ul').adidoCarousel({ autoStart: false, pager: true, pagerElement: '#homeCarouselPager', pagerStyle: 'numeric' });
    $('#homeFeedsCarousel').adidoCarousel({ autoStart: false, buttons: false, mode: 'instant', pager: true, pagerAuto: false, pagerElement: '#homeFeedsPager' });
    $('#testimonialCarousel ul').adidoCarousel({ buttons: false });
    $('#homeNewsCarousel ul').adidoCarousel({ buttons: false });
    $('#rightColNews ul').adidoCarousel({ resizeMask: true, horizontal: false });



    $('div.productGrid div.prodPrice').each(function() {
        var txt = $(this).html();
        txt = txt.replace("Our", "DVD");
        $(this).html(txt);
    });

    $('.glint').adidoGlint({ animSpeed: 800 });

    $('p.dropDownLnk a').click(function(e) {
        e.preventDefault();
        $('div.dropDownContent').slideToggle();
    });

    $('#basketTabLnk a').click(function(e) {
        e.preventDefault();
        $('#basketTabCont').slideToggle();
    });

    bindPopups();

    $('div.catListing div.productBox:odd').addClass('altRow');

    var h = 0;
    $('div.productBoxMid').each(function() {
        var th = $(this).height();
        if (th > h) {
            h = th;
        }
    }).height(h);

    $('.prodListingImg').corners();
    $('td.basketThumb a').corners();
    $('div.schoolDelivery div.performanceImg').corners();
    $('div#productImage').corners();

    /* Rounded images */
    $('img.rounded').each(function(i, e) {
        $(this).wrap('<div class="imgWrap"></div>');
        if ($(this).hasClass('right')) {
            $(this).parent().addClass('right');
        } else if ($(this).hasClass('left')) {
            $(this).parent().addClass('left');
        }
        var src = $(this).attr('src');
        $(this).parent().css({ 'background-image': 'url(' + src + ')', 'background-repeat': 'no-repeat', 'background-position': 'top left' });
        $(this).css({ 'visibility': 'hidden' });
    });

    $('select.ddlSource').change(function() {
        var v = $(this).val();
        if (v == 'other') {
            $(this).siblings('.textSource').show();
        } else {
            $(this).siblings('.textSource').hide();
        }
    }).change();


    $('.datePicker').datepicker({ dateFormat: 'dd/mm/yy' });


    $(':first-child').addClass('first');
    $(':last-child').addClass('last');
    $('a[rel=newWindow]').attr('target', '_blank');
});

function bindPopups() {

    $('div.catPopup').remove().appendTo('body > form:first-child');
    $('div.productPopup').remove().appendTo('body > form:first-child');
    
    $('div.catListing div.productBox').live("click", function(e) {
        e.preventDefault();
        showOverlay($('div.catPopup'));
        var href = $(this).find('a.readMore').attr('href');
        $('.CatHref').val(href);
        setCatID($(this).find('a.readMore').attr('catid'), $(this).find('a.readMore').attr('href'));
    });

    $('input.btnAddToBasket').live("click", function(e) {
        e.preventDefault();
        showOverlay($('div.productPopup'));
    });
}

function setCatID(id, href) { }

// Close button - Craig CT
function closePopup() {
    hideOverlay($('div.catPopup'));
}

