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;
}

$(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'
        });
    }

    $('.searchBox input.textBox').focus(function() {
        var t = $(this).attr('rel');
        var v = $(this).val();
        if (v == t) {
            $(this).val('');
        }
    }).blur(function() {
        var t = $(this).attr('rel');
        var v = $(this).val();
        if (v == '') {
            $(this).val(t);
        }
    });

    $('input.textClear').focus(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == t) {
            $(this).val('');
        }
    }).blur(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == '') {
            $(this).val(t);
        }
    });

    $('input.txbQty').focus(function() { }).blur(function() {
        var v = $(this).val();
        if (isNaN(v)) {
            $(this).val(0);
        }
    });

    $('div.imgBox ul').adidoCarousel({ buttons: false, mode: 'fade' });

    $('div#blogMain h3.post-title a').bigTarget({ clickZone: 'div:eq(0)' });
    // $('div.catListing a.lnkImage').bigTarget({ clickZone: 'div:eq(0)' });

    $('div#contentFrame, div#contentFrameHome, div#homeBlog, div#blog-header, div#blogMain, div#rightCol div.widget, div.questionBox').corners();

    $('img.backgroundimage').maxImage({
        isBackground: true,
        slideShow: false,
        verticalAlign: 'top',
        slideShowTitle: false,
        maxFollows: 'height',
        position: 'fixed',
        zIndex: 1
    });

    var h = $('#homeFacebook').outerHeight(true);
    h = h + $('#homeLink').outerHeight(true);
    var blogH = h - 24;
    $('#homeBlog').height(blogH);

    $('div.catListing div.productBox').hover(function() {
        $(this).css({ zIndex: 4 });
        $(this).find('.catDesc').show();
    }, function() {
        $(this).css({ zIndex: 2 });
        $(this).find('.catDesc').hide();
    });

    $('a.btnQtySub').click(function(e) {
        var txb = $(this).siblings('.txbQty');
        var v = txb.val();
        if (v > 0) {
            v--;
            txb.val(v);
        }
    });
    $('a.btnQtyAdd').click(function(e) {
        var txb = $(this).siblings('.txbQty');
        var v = txb.val();
        v++;
        txb.val(v);
    });

    $('.miniBasketBtn').click(function(e) {
        e.preventDefault();
        $('.miniBasketDrop').slideToggle();
    });

    $('div.questionBox h2').click(function(e) {
        e.preventDefault();
        $(this).next().slideToggle();
    }).css('cursor', 'pointer').next().hide();

    $('input.textClear').each(function() {
        var v = $(this).val();
        $(this).attr('title', v);
    });
    $('input.textClear').focus(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == t) {
            $(this).val('');
        }
    }).blur(function() {
        var t = $(this).attr('title');
        var v = $(this).val();
        if (v == '') {
            $(this).val(t);
        }
    });

    $('textarea.textClear').each(function() {
        var v = $(this).text();
        $(this).attr('title', v);
    });
    $('textarea.textClear').focus(function() {
        var t = $(this).attr('title');
        var v = $(this).text();
        if (v == t) {
            $(this).text('');
        }
    }).blur(function() {
        var t = $(this).attr('title');
        var v = $(this).text();
        if (v == '') {
            $(this).text(t);
        }
    });

    $('div.productRow div.description')
    .wrapInner('<div class="descriptionMid"></div>')
    .prepend('<div class="descriptionTop"></div>')
    .append('<div class="descriptionBtm"></div>');

    $('div.productRow div.item').each(function() {
        var desc = $(this).next('.description').text();
        if (desc != "") {
            span = $('<span class="desc"></span>');
            $(this).wrapInner(span);
        }
    });

    $('div.productRow div.item').hover(function() {
        var box = $(this).next('div.description');
        var text = box.children('.descriptionMid').text();
        if (text != "") {
            box.show();
        }
    }, function() {
        var box = $(this).next('div.description');
        box.hide();
    });

    $('div.checkout input.dateBox').datepicker({ beforeShowDay: function(date) {
    var day = date.getDay();
        return [(day > 0), ''];
    }, dateFormat: 'dd/mm/yy', onSelect: function(t) {
        // alert(t);
        var myDate = t.split("/");
        // alert(myDate[0] + " | " + myDate[1] + " | " + myDate[2]);
        var $parent = $(this).parent();
        $parent.children('input:eq(0)').val(myDate[0]);
        $parent.children('input:eq(1)').val(myDate[1]);
        $parent.children('input:eq(2)').val(myDate[2]);
    } 
    });

    $(':first-child').addClass('first');
    $(':last-child').addClass('last');
    $('a[rel=newWindow]').attr('target', '_blank');
});
