document.write( '<link rel="stylesheet" href="/assets/css/javascript.css" type="text/css" media="all" />' );

Epson = new Object;
MMFactory = null;


// jQuery Document Loader
jQuery( document ).ready( function()
{
	// get assets path
	Epson.Path = jQuery( '#MastHead .mastheadLogo img' ).length ? jQuery( '#MastHead .mastheadLogo img' ).attr( 'src' ).substr( 0, jQuery( '#MastHead .mastheadLogo img' ).attr( 'src' ).indexOf( 'images/' ) ) : '';

	// setup search
	if ( Epson.Search ) jQuery( '#SiteSearch, .liveSearch' ).each( function() { new Epson.Search( this ) } );

	// setup carousel
	if ( Epson.Carousel && jQuery( '#Carousel' ).length ) Epson.Carousel.setup();

	// setup product data for various components
	if ( Epson.ProductBrowser && Epson.ProductBrowser.data.length ) Epson.ProductBrowser.loadProductData();

	// setup product browser
	if ( Epson.ProductBrowser && jQuery( '#ProductBrowser' ).length ) Epson.ProductBrowser.setup();

	// setup product comparisons
	if ( Epson.ProductComparison && jQuery( '#CompareItems' ).length ) Epson.ProductComparison.setup();	

	// setup pro graphics showcase
	if ( Epson.ProGraphics && jQuery( '#ProShowCase' ).length ) Epson.ProGraphics.setup();

	// setup category tabs
	if ( Epson.Category && jQuery( '#Content .categoryTabs .categoryNavigation' ).length ) Epson.Category.setup();

	// setup where to buy
	if ( Epson.WhereToBuy ) jQuery( '.whereToBuy' ).each( function() { new Epson.WhereToBuy( this ) } );

	// set up main basket
	if ( Epson.MainBasket && jQuery( '#ShoppingBasket' ).length ) Epson.MainBasket.setup();

	// set up main basket
	if ( Epson.DynamicBasket && jQuery( '#ConfigureBasket' ).length ) Epson.DynamicBasket.setup();

	// set up faq form
	if ( Epson.FAQSearch && jQuery( '#FAQSearch' ).length ) Epson.FAQSearch.setup();

	// set up not my product links
	jQuery( '.notMyProduct' ).each( function() { new Epson.UnRegisterProduct( this ) } );

	// set up product registration
	if ( Epson.Registration && jQuery( '#RegistrationSearch' ).length ) Epson.Registration.setup();
	if ( Epson.Forms.Reg && jQuery('#GuestUser').length ) Epson.Forms.Reg.setup();

	// set up store finder fields
	if ( Epson.WhereToBuy ) jQuery( '.storeFinder' ).each( function() { new Epson.WhereToBuy( this ) } );

	// set up nugget layer triggers
	if ( Epson.Nuggets ) jQuery( '.nuggetParent' ).each( Epson.Nuggets.setup );

	// newsletter module
	if ( jQuery( '#NewsletterSignup' ).length ) Epson.Newsletter.setup();

	// Configuration/Ink Supplies/Support page Terms and Conditions
	if ( jQuery( '#Configuration, #ConsumableProduct, #ProductRegistration .registerUser' ).length ) Epson.Forms.HiddenTerms.setup( jQuery( '#TermsConditions' ), jQuery( '#f_terms_conditions' ) );	

	// support select os
	if ( jQuery('#Support #f_selectos').length ) jQuery( '#Support #f_selectos' ).bind( 'change', function() { jQuery( 'form#selectOS' ).submit() } );

	// expandable consumable lists
	jQuery( '.toggleConsumableData' ).each( function() { jQuery( this ).bind( 'click', function(e) { var table = jQuery( this ).parent().find( '.collapsibleConsumableData' ); if ( table.hasClass( 'open' ) ) { jQuery( this ).removeClass( 'buttonMinus' ).addClass( 'buttonPlus' ).find( 'span' ).text( Epson.Localisation.CollapsibleConsumables.TXT001 ); table.animate( { height:0 }, 300, 'swing', function() { table.hide() } ).removeClass( 'open' ) } else { jQuery( this ).removeClass( 'buttonPlus' ).addClass( 'buttonMinus' ).find( 'span' ).text( Epson.Localisation.CollapsibleConsumables.TXT002 ); if ( !table.data( 'height' ) ) { table.css( { height:'auto' } ); table.data( 'height', table.height() ); table.css( { height:0 } ) }; table.show().animate( { height:table.data( 'height' ) }, 300, 'swing' ).addClass( 'open' ) }; e.preventDefault() } ) } );

	// set up bundle promos
	jQuery( '.bundlePromoRadio' ).each( function() { jQuery( this ).parents( '.bundlePromo' ).bind( 'click', function(e) { if(typeof(e.target.name) == 'undefined') {jQuery( '.bundlePromoRadio[@name="' + jQuery( this ).find( 'input.bundlePromoRadio' ).attr( 'name' ) + '"]' ).parents( '.bundlePromo' ).removeClass( 'selected' ); jQuery( this ).addClass( 'selected' ).find( 'input.bundlePromoRadio' ).click()} } ) } );
	
	//pagination for articles
	if ( jQuery('.keywordSearchResult, ul.articleSearchResults, .reviews ul.more').length) Epson.SearchPagination.setup();

	// consumable product items show all
	jQuery( '.cpiShowAll' ).each( function() { jQuery( this ).bind( 'click', function(e) { jQuery( this ).parents( '.consumableProList' ).find( '.consumableProListContent.hidden' ).css( { display:'block' } ); jQuery( this ).parent().remove(); e.preventDefault() } ) } );
	jQuery( '.subShowAll' ).each( function() { jQuery( this ).bind( 'click', function(e) { jQuery( this ).parents( '.consumableProList' ).find( '.consumableProListContent ul.productList .hidden' ).css( { display:'block' } ); jQuery( this ).parent().remove(); e.preventDefault() } ) } );

	// review list
	if ( jQuery('.reviews').length ) Epson.Reviews.setup();
	
	// receive alert functionality
	if ( Epson.ProductAlerts ) jQuery( '.alertNotification' ).each( function() { new Epson.ProductAlerts( jQuery( this ) ) } );

	// Accordions
	if ( jQuery( '.heroNavigation' ).length ) jQuery( 'ul.heroNavigation' ).accordion( { active: 'li.selected', header: 'h4', alwaysOpen: false, animated:'easeslide', autoHeight:false, navigation:true, navigationFilter: function() { return jQuery( this.parentNode ).hasClass( 'selected' ) } } );

	// Fragment Popups
	if ( Epson.UI.Popup ) jQuery( '.triggerPopup' ).each( function() { jQuery( this ).bind( 'click', Epson.UI.Popup.loadGeneric ) } );

	// set up download based on cookie
	if ( jQuery('.buttonDownload').length ) Epson.Download.setPopup();

	// Close Popups
	 jQuery( '#Popup' ).each( function() { Epson.UI.Popup.element = jQuery( this ); jQuery( this ).find( '.closePopup' ).bind( 'click', Epson.UI.Popup.close ) } );
	
	// Print funcitonality
	jQuery( '.printPage' ).each( function() { jQuery( this ).bind( 'click', function(e) { window.print(); e.preventDefault() } ) } );

	// set up teaser carousels
	if ( Epson.TeaserCarousel ) jQuery( '.teaserCarousel' ).each( function() { new Epson.TeaserCarousel( this ) } );

	// set up Collapsable Modules
	jQuery( '.genericCollapsibleModule .header, .genericCollapsibleSection .header' ).each( function( i, item ) { new Epson.CollapsableModule( this, jQuery( '.collapsibleContent' )[i] ) } );

	// Language Dropdown
	if ( jQuery( '#selCountryDropdown' ).length )	Epson.LanguageDropdown.setup();

	// Secondary Navigation Dropdowns
	if ( jQuery( '#MastHead .secondaryNavigation .dropdown' ).length ) jQuery( '#MastHead .secondaryNavigation .dropdown' ).each( function() { new Epson.SecondaryNavDropdowns( this ) } );

	// Prefilling the gender if already selected before
	if(typeof prefilledGender!="undefined"){
		if(prefilledGender=='male'){
			Epson.Forms.AutoGender.gender = 0;
		} else {
			Epson.Forms.AutoGender.gender = 2;
		}
	}
	// set up forms
	if ( jQuery( 'form' ).length ) Epson.Forms.setup();

	// expandable lists
	jQuery( '.elShowAll' ).each( Epson.GenericExpandToggle );

	// Clonable blocks
	jQuery( 'form .cloneBlock' ).each( function() { Epson.cloneBlock( this, 'click' ) } );

	// Generic Dropdowns
	jQuery( 'select.jsDropdown' ).each( function() { var dropdown = this; setTimeout( function() { new Epson.GenericDropdown( dropdown ) }, 1 ) } );
	jQuery( 'select.jsProductDropdown' ).each( function() { var dropdown = this; setTimeout( function() { new Epson.ProductDropdown( dropdown ) }, 1 ) } );
	
	
} );



Epson.LanguageDropdown =
{
	url:'',
	timer:null,
	dropdown_element: null,
	dropdown_menu: null,

	setup: function()
	{
		Epson.LanguageDropdown.dropdown_element = jQuery( '#selCountryDropdown' );

		// bind events to the selects
		jQuery( Epson.LanguageDropdown.dropdown_element.find( 'select' )[0] ).bind( 'change', Epson.LanguageDropdown.changeCountry );
		jQuery( Epson.LanguageDropdown.dropdown_element.find( 'select' )[1] ).bind( 'change', Epson.LanguageDropdown.changeLanguage );

		// create dropdown
		Epson.LanguageDropdown.dropdown_menu = jQuery( '<div class="selCountryContainer genericRoundedCorners"><div class="top"><div class="tl"></div><div class="tr"></div><div class="t"></div></div><div class="content clear"></div><div class="bottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div></div>' );
		Epson.LanguageDropdown.dropdown_menu.find( '.content' ).append( Epson.LanguageDropdown.dropdown_element.find( 'select' ) );
		Epson.LanguageDropdown.dropdown_menu.find( 'select' ).wrap( '<div class="row"></div>' );
		Epson.LanguageDropdown.dropdown_menu.css( { display:'none' } );

		Epson.LanguageDropdown.url = jQuery( '#UserLinks form' ).attr( 'action' );
		Epson.LanguageDropdown.dropdown_element.empty();
		Epson.LanguageDropdown.dropdown_element.append( jQuery( '<a href="#">' + Epson.LanguageDropdown.dropdown_menu.find( 'select:first option[@selected]' ).text() + '</a>' ).bind( 'click', Epson.LanguageDropdown.open ) );

		jQuery( '#Container' ).append( Epson.LanguageDropdown.dropdown_menu );
	},

	changeCountry: function(e)
	{
		window.location = 'http://' + this.value;

		e.preventDefault();
	},

	changeLanguage: function(e)
	{
		window.location = '/' + this.value;

		e.preventDefault();
	},

	open: function(e)
	{
		// position menu
		var position = Epson.LanguageDropdown.dropdown_element.offset( { border:true, padding:true } );
		var dimensions = [ Epson.LanguageDropdown.dropdown_element.outerWidth(), Epson.LanguageDropdown.dropdown_element.outerHeight() ];
		Epson.LanguageDropdown.dropdown_menu.css( { display:'block', position:'absolute', top:position.top+dimensions[1]+5+'px', left:position.left+dimensions[0]+'px'  } );
		Epson.LanguageDropdown.dropdown_menu.css( { left:parseInt( Epson.LanguageDropdown.dropdown_menu.css( 'left' ) )-Epson.LanguageDropdown.dropdown_menu.width()+'px' } );

		// add close event
		setTimeout( function() { jQuery( 'body' ).bind( 'click', Epson.LanguageDropdown.timeClose ) }, 1);

		// remove open event
		Epson.LanguageDropdown.dropdown_element.find( 'a' ).unbind( 'click', Epson.LanguageDropdown.open )

		// add unbubble event
		Epson.LanguageDropdown.dropdown_menu.bind( 'click', function() { setTimeout( function() { clearTimeout( Epson.LanguageDropdown.timer ); Epson.LanguageDropdown.timer=null }, 1 ) } );

		e.preventDefault();
	},

	timeClose: function()
	{
		Epson.LanguageDropdown.timer = setTimeout( Epson.LanguageDropdown.close, 10 );
	},

	close: function()
	{
		if ( Epson.LanguageDropdown.timer ) // IE fix
		{
			jQuery( '#Container .selCountryContainer' ).css( { display:'none' } );
	
			// remove close event
			jQuery( 'body' ).unbind( 'click', Epson.LanguageDropdown.timeClose );
	
			// add open event
			Epson.LanguageDropdown.dropdown_element.find( 'a' ).bind( 'click', Epson.LanguageDropdown.open )
		}
	}
}


Epson.SecondaryNavDropdowns = function( element )
{
	var _element = element;
	var _submenu;
	var _ddelement = null;
	var _width = 0;
	var _timer;

	setup();


	function setup()
	{
		_element = jQuery( element );
		_submenu = _element.find( 'ul' );

		// calculate max width
		var tmp = jQuery( '<div class="jsDropdownMenu" style="position:static"><ul><li style="display:inline; padding:0"></li></ul></div>' );
		jQuery( '#Container' ).append( tmp );
		for ( var x = 0; x < _submenu.find( 'li' ).length; x++ )
		{
			tmp.find( 'li' ).text( jQuery( _submenu.find( 'li' )[x] ).text() );
			if ( tmp.find( 'li' )[0].offsetWidth > _width ) _width = tmp.find( 'li' )[0].offsetWidth + 20;
		}
		tmp.remove();

		_element.bind( 'mouseover', open );
	}
	
	function open(e)
	{
		// get position for dropdown
		var jquery_offset = _element.offset( { border:true, padding:true } );
		_position = [ jquery_offset.left-10, jquery_offset.top + _element.outerHeight() ];

		// create dropdown
		_ddelement = jQuery( '<div class="jsDropdownMenu genericRoundedCorners category"><div class="bottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div></div>' ).css( { width:_width+20 });
		_ddelement.css( { top:_position[1]+7+'px', left:_position[0]+'px' } );
		_submenu.addClass( 'content' ).insertBefore( _ddelement.find( '.bottom' ) );

		// append dropdown to container
		jQuery( '#Container' ).append( _ddelement );

		// set events
		_element.unbind( 'mouseover', open );
		setTimeout( function() { _element.bind( 'mouseover', cancelCloseTimer ) }, 1);
		_ddelement.bind( 'mouseover', cancelCloseTimer );
		setTimeout( function() { _element.bind( 'mouseout', setCloseTimer ) }, 1);
		_ddelement.bind( 'mouseout', setCloseTimer );
		// jQuery( 'body' ).bind( 'click', close ); 

		e.preventDefault();
	}
	
	function setCloseTimer()
	{
		_timer = setTimeout( close, 250 );
	}
	
	function cancelCloseTimer()
	{
		clearTimeout( _timer );
	}
	
	function close()
	{
		// remove menu
		_element.append( _ddelement.find( 'ul' ) );
		_ddelement.remove();

		// set events
		setTimeout( function() { _element.bind( 'mouseover', open ) }, 1);
		_element.unbind( 'mouseover', cancelCloseTimer );
		_ddelement.unbind( 'mouseover', cancelCloseTimer );
		_element.unbind( 'mouseout', setCloseTimer );
		_ddelement.unbind( 'mouseout', setCloseTimer );
		jQuery( 'body' ).unbind( 'click', close );
	}
}


// GENERIC DROPDOWNS
Epson.GenericDropdown = function( element )
{
	var _self = this;
	this.element = this.element ? this.element : element;
	this.field;
	this.ddelement = null;
	this.options = this.options ? this.options : [];
	this.selectedIndex = 0;
	this.width = 0;
	this.position = [];
	this.change = [];
	this.attributes = {};
	this.className = this.className ? this.className : 'jsDropdown';
	this.value = null;
	this.keySelected = 0;

	this.eventOpen = this.eventOpen ? this.eventOpen : function(e) { _self.open(e) };
	this.eventSelect = this.eventSelect ? this.eventSelect : function(e) { _self.select(e) };
	this.eventKeydown = this.eventKeydown ? this.eventKeydown : function(e) { _self.keydown(e) };
	this.eventClose = this.eventClose ? this.eventClose : function(e) { _self.close(e) };
	this.eventCancel = this.eventCancel ? this.eventCancel : function(e) { _self.cancel(e) };

	if ( this.element )
	{
		// save options data
		jQuery( this.element ).find( 'option' ).each( function(i)
		{
			if ( !_self.options[i] ) _self.options[i] = [];
			_self.options[i][0] = jQuery( this ).val();
			_self.options[i][1] = jQuery( this ).text();
			_self.options[i][2] = jQuery( this ).attr( 'class' )

			if ( this.selected ) _self.selectedIndex = i;
		} );

		// get name
		var name = jQuery( this.element ).attr( 'name' );

		// save attributes
		var attributes = this.element.attributes;
		for ( var x = 0; x < attributes.length; x++ ) this.attributes[ attributes[x].nodeName ] = attributes[x].nodeValue;

		// save class names
		this.className = this.className + ' ' + this.element.className.replace( this.className, '' );
	
		// copy over events
		var events = jQuery.data( this.element, 'events' ) ? jQuery.data( this.element, 'events' )[ 'change' ] : null;
		if ( events ) for ( var handler in events ) this.change.push( events[handler] );

		// calculate max width
		var tmp = jQuery( '<div class="jsDropdownMenu" style="position:static"><ul><li style="display:inline; padding:0"></li></ul></div>' );
		jQuery( '#Container' ).append( tmp );
		for ( var x = 0; x < this.options.length; x++ )
		{
			tmp.find( 'li' ).text( this.options[x][1] );
			if ( tmp.find( 'li' )[0].offsetWidth > this.width ) this.width = tmp.find( 'li' )[0].offsetWidth;
		}
		tmp.remove();
	
		// draw styled dropdown
		this.draw();

		// save reference to object in jQuery
		this.element.data( 'jDropdown', _self );

		// create hidden field with data
		this.field = jQuery( '<input type="hidden" name="' + name + '" value="' + this.options[this.selectedIndex][0] + '" id="'+name+'id"/>' );
		this.element.after( this.field );
	
		// save data into jQuery
		this.element.data( 'name', name );
		this.element.data( 'value', this.options[this.selectedIndex][0] );
		this.element.val( this.options[this.selectedIndex][0] );
	
		// save selected value
		this.value = this.options[this.selectedIndex][0];

		// bind window close event to replace normal selects for server data
		// jQuery( window ).bind( 'beforeunload', unload );
	}
}

Epson.GenericDropdown.prototype.draw = function()
{
	var self = this;

	// get id if there is one
	var id = ( this.element.id ) ? this.element.id : null;

	// build up dropdown
	var width = ( jQuery( this.element ).css( 'width' ) != 'auto' ) ? ( parseInt( jQuery( this.element ).css( 'width' ) ) > this.width ) ? parseInt( jQuery( this.element ).css( 'width' ) ) - 27 : this.width + 5 : this.width + 5;
	
	// setting max width for the dropdowns
	width = width > 420 ? 420 : width;

	var dropdown = jQuery( '<a href="#" class="' + this.className + '"><span>' + this.options[this.selectedIndex][1] + '</span></a>' );

	// bind events
	dropdown.bind( 'click', self.eventOpen );
	dropdown.bind( 'keydown', self.eventKeydown );

	dropdown.find( 'span' ).css( { width:width+'px' } );
	if ( id ) dropdown.attr( 'id', id );

	// replace existing dropdown with styled one
	var select = jQuery( this.element );
	this.element = jQuery( dropdown );
	select.replaceWith( this.element );
}


Epson.GenericDropdown.prototype.unload = function()
{
	var select = jQuery( '<select></select>' ).css( { visibility:'hidden' } );
	
	// copy back attributes
	jQuery.each( this.attributes, function(key, value) { select[0].setAttribute( key, value ) } );

	// add in options
	jQuery.each( this.options, function() { select.append( jQuery( '<option value="' + this[0] + '">' + this[1] + '</option>' ) ) } );

	// set selected option
	select.find( 'option' )[ this.selectedIndex ].selected = 'selected';

	// replace jsDropdown
	this.element.replaceWith( select.removeClass( 'jsDropdown' ) );
	this.element = select;
}

Epson.GenericDropdown.prototype.open = function(e)
{
	var self = this;

	if ( this.element.attr( 'disabled' ) != 'disabled' )
	{
		// get position for dropdown
		var in_popup = this.element.parents( '#Popup' ).length ? true : false;
		var jquery_offset = this.element.offset( { border:true, padding:true } );
		this.position = [ jquery_offset.left, jquery_offset.top + this.element.outerHeight() ];
		var width = ( this.element.innerWidth() > this.width ) ? this.element.innerWidth() : this.width+20;
		var top = this.position[1];
		if ( in_popup && !( jQuery.browser.msie && jQuery.browser.version < 7 ) ) top = top - jQuery( document ).scrollTop();

		// create dropdown
		this.ddelement = jQuery( '<div class="jsDropdownMenu genericRoundedCorners"><ul class="content"></ul><div class="bottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div></div>' ).css( { width:width });
		this.ddelement.css( { top:top+'px', left:this.position[0]+'px' } );
		if ( in_popup && !( jQuery.browser.msie && jQuery.browser.version < 7 ) ) this.ddelement.css( { position:'fixed' } );
		if ( jQuery.browser.msie && jQuery.browser.version < 7 && in_popup ) { var dd = this.ddelement; jQuery( window ).bind( 'scroll', function() { dd.css( { top:top + jQuery( document ).scrollTop() } ) } ) };
		for ( var x = 0; x < this.options.length; x++ )
		{
			var item = jQuery( '<li>' + this.options[x][1] + '</li>' );

			if ( x == this.selectedIndex ) item.addClass( 'selected' );

			if (this.options[x][2]) item.addClass( this.options[x][2] )

			item.bind( 'click', self.eventSelect );
			item.bind( 'mouseover', function(e)
			{
				self.ddelement.find( 'li.selected' ).removeClass( 'selected' );
				jQuery( this ).addClass( 'selected' );

				self.keySelected = self.ddelement.find( 'li' ).index( this );
			} );

			this.ddelement.find( 'ul' ).append( item );
		}

		// append dropdown to container
		jQuery( '#Container' ).append( this.ddelement );

		// remove open event and add cancel event
		this.element.unbind( 'click', self.eventOpen );
		this.element.bind( 'click', self.eventCancel );
	
		// add close event
		setTimeout( function() { jQuery( 'body' ).bind( 'click', self.eventClose ) }, 1);
	}

//	e.stopPropagation();
	e.preventDefault();
}

Epson.GenericDropdown.prototype.keydown = function(e)
{
	if ( e.keyCode == 32 ) // space
	{
		if ( !this.ddelement )
		{
			this.keySelected = this.selectedIndex;

			this.open(e);
		}
		else
		{
			this.ddelement.find( 'li.selected' ).click();

			e.preventDefault();
		}
	}
	else if ( e.keyCode == 40 ) // down
	{
		if ( ++this.keySelected > this.options.length - 1 ) this.keySelected = 0;

		if ( this.ddelement )
		{
			this.ddelement.find( 'li.selected' ).removeClass( 'selected' );
			this.ddelement.find( 'li:eq(' + this.keySelected + ')' ).addClass( 'selected' );
		}
		else
		{
			this.selectedIndex = this.keySelected;

			// set text dropdown
			this.element.find( 'span' ).text( this.options[this.selectedIndex][1] );
	
			// save value in jQuery
			this.element.data( 'value', this.options[this.selectedIndex][0] );
	
			// save selected value
			this.value = this.options[this.selectedIndex][0];
			this.element.val( this.options[this.selectedIndex][0] );
			this.field.val( this.options[this.selectedIndex][0] );
	
			// perform custom event listeners if they exist
			e.target = this.element[0];
			if ( this.change.length ) for ( var x = 0; x < this.change.length; x++ ) this.change[x].call( this, e);
		}

		e.preventDefault();
	}
	else if ( e.keyCode == 38 ) // up
	{
		if ( --this.keySelected < 0 ) this.keySelected = this.options.length - 1;

		if ( this.ddelement )
		{
			this.ddelement.find( 'li.selected' ).removeClass( 'selected' );
			this.ddelement.find( 'li:eq(' + this.keySelected + ')' ).addClass( 'selected' );
		}
		else
		{
			this.selectedIndex = this.keySelected;

			// set text dropdown
			this.element.find( 'span' ).text( this.options[this.selectedIndex][1] );
	
			// save value in jQuery
			this.element.data( 'value', this.options[this.selectedIndex][0] );
	
			// save selected value
			this.value = this.options[this.selectedIndex][0];
			this.element.val( this.options[this.selectedIndex][0] );
			this.field.val( this.options[this.selectedIndex][0] );
	
			// perform custom event listeners if they exist
			e.target = this.element[0];
			if ( this.change.length ) for ( var x = 0; x < this.change.length; x++ ) this.change[x].call( this, e);
		}

		e.preventDefault();
	}
	else if ( e.keyCode == 13 ) // return
	{
		this.ddelement.find( 'li:eq(' + this.keySelected + ')' ).click();
		
		e.preventDefault();
	}
	else if ( e.keyCode == 9 && this.ddelement ) // tab
	{
		this.ddelement.find( 'li:eq(' + this.keySelected + ')' ).click();
	}
}

Epson.GenericDropdown.prototype.select = function(e)
{
	// get index of selected item
	var new_selection = -1;
	var target_li = e.target;
	if ( target_li.nodeName != 'LI' ) target_li = jQuery( target_li ).parents( 'li' )[0];
	var list_items = this.ddelement.find( 'li' );
	for ( var x = 0; x < list_items.length; x++ ) if ( list_items[x] == target_li ) { new_selection = x; break }

	if ( new_selection != this.selectedIndex )
	{
		this.selectedIndex = new_selection;

		// set text dropdown
		this.element.find( 'span' ).html( this.options[this.selectedIndex][1] );

		// save value in jQuery
		this.element.data( 'value', this.options[this.selectedIndex][0] );

		// save selected value
		this.value = this.options[this.selectedIndex][0];
		this.element.val( this.options[this.selectedIndex][0] );
		this.field.val( this.options[this.selectedIndex][0] );

		// perform custom event listeners if they exist
		e.target = this.element[0];
		if ( this.change.length ) for ( var x = 0; x < this.change.length; x++ ) this.change[x].call( this, e);
	}

	this.eventClose(e);

	e.stopPropagation();
	e.preventDefault();
}

Epson.GenericDropdown.prototype.close = function(e)
{
	var self = this;

	this.ddelement.remove();
	delete this.ddelement;

	// remove close event
	jQuery( 'body' ).unbind( 'click', self.eventClose );

	// add open event and remove cancel event
	setTimeout( function() { self.element.bind( 'click', self.eventOpen ) }, 1 );
	this.element.unbind( 'click', self.eventCancel );

	if (e) e.preventDefault();
}
	
Epson.GenericDropdown.prototype.cancel = function(e)
{
	this.eventClose(e);

	e.stopPropagation();
}

Epson.GenericDropdown.prototype.reset = function( dropdown )
{
	var select = jQuery( '<select></select>' );
	
	// copy back attributes
	jQuery.each( this.attributes, function(key, value) { select[0].setAttribute( key, value ) } );
	if ( dropdown.id ) select[0].id = dropdown.id;

	// add in options
	jQuery.each( this.options, function() { select.append( jQuery( '<option value="' + this[0] + '">' + this[1] + '</option>' ) ) } );

	// set selected option
	select.find( 'option' )[ this.selectedIndex ].selected = 'selected';

	// replace jsDropdown
	jQuery( dropdown ).replaceWith( select.removeClass( 'jsDropdown' ) );

	// remove adjacent hidden field
	select.next( 'input[type=hidden]' ).remove();

	return select[0];
}


// PRODUCT DROPDOWNS - inherit off GENERIC DROPDOWNS
Epson.ProductDropdown = function( element )
{
	var _self = this;
	this.base = Epson.GenericDropdown;
	this.element = element;
	this.className = 'jsProductDropdown';
	this.image = '';

	this.eventOpen = function(e) { _self.open(e) };
	this.eventSelect = function(e) { _self.subSelect(e) };
	this.eventClose = function(e) { _self.close(e) };
	this.eventCancel = function(e) { _self.cancel(e) };

	// get images
	jQuery( this.element ).find( 'option' ).each( function(i)
	{
		var image = this.className.match( /pd-image-([^\s]+)/ );
		var url = this.className.match( /pd-url-([^\s]+)/ );
		var alt = this.className.match( /pd-alt-([^\s]+)/ );

		if ( !_self.options[i] ) _self.options[i] = [];
		_self.options[i][2] = image ? image[1] : null;
		_self.options[i][3] = url ? url[1] : '#';
		_self.options[i][4] = alt ? alt[1] : '';
	} );

	this.image = _self.options[0][2];

	// call the parent constructor
	this.base();
}
Epson.ProductDropdown.prototype = new Epson.GenericDropdown;

Epson.ProductDropdown.prototype.draw = function()
{
	var self = this;

	// get id if there is one
	var id = ( this.element.id ) ? this.element.id : null;

	// build up dropdown
	var width = ( jQuery( this.element ).css( 'width' ) != 'auto' ) ? ( parseInt( jQuery( this.element ).css( 'width' ) ) > this.width ) ? parseInt( jQuery( this.element ).css( 'width' ) ) : this.width + 5 : this.width + 5;
	var dropdown = jQuery( '<div class="' + this.className + '"><strong><img src="' + this.image +  '" alt="' +this.options[this.selectedIndex][4]+ '"/><span>' + this.options[this.selectedIndex][1] + '</span></strong></div>' ).bind( 'click', self.eventOpen );
	if ( document.addEventListener ) dropdown.find( 'span' ).css( { width:width-24 } );
	else dropdown.css( { width:width-24 } );
	
	if ( id ) dropdown.attr( 'id', id );

	// replace existing dropdown with styled one
	var select = jQuery( this.element );
	this.element = jQuery( dropdown );
	select.replaceWith( this.element );
}

Epson.ProductDropdown.prototype.open = function(e)
{
	var self = this;

	// get position for dropdown
	var jquery_offset = this.element.offset( { border:false, padding:false } );
	this.position = [ jquery_offset.left, jquery_offset.top + this.element.outerHeight() ];
	var width = ( this.element.innerWidth() > this.width ) ? this.element.innerWidth() : this.width+20;

	// create dropdown
	this.ddelement = jQuery( '<div class="jsDropdownMenu jsPropductDropdownMenu genericRoundedCorners"><ul class="content"></ul><div class="bottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div></div>' ).css( { width:width });
	this.ddelement.css( { top:this.position[1]+'px', left:this.position[0]+'px' } );
	for ( var x = 0; x < this.options.length; x++ )
	{
		var image = this.options[x][2] ? '<img src="' + this.options[x][2].match( /pd-image-([^\s]+)/ )[1] +  '" alt="'+ this.alt +'" />' : '';
		if ( x == this.selectedIndex ) this.ddelement.find( 'ul' ).append( jQuery( '<li class="selected">' + image + '<span>' + this.options[x][1] + '</span></li>' ).bind( 'click', self.eventSelect ) );
		else this.ddelement.find( 'ul' ).append( jQuery( '<li>' + image + '<span>' + this.options[x][1] + '</span></li>' ).bind( 'click', self.eventSelect ) );
	}

	// append dropdown to container and animate
	jQuery( '#Container' ).append( this.ddelement );
	if ( !jQuery.browser.msie ) this.ddelement.css( { opacity:0 } ).animate( { opacity:1 }, 200, 'swing' );

	// remove open event and add cancel event
	this.element.unbind( 'click', self.eventOpen );
	this.element.bind( 'click', self.eventCancel );

	// add close event
	setTimeout( function() { jQuery( 'body' ).bind( 'click', self.eventClose ) }, 1);

	e.stopPropagation();
	e.preventDefault();
}

Epson.ProductDropdown.prototype.subSelect = function(e)
{
	// get index of selected item
	var new_selection = -1;
	var target_li = e.target;
	if ( target_li.nodeName != 'LI' ) target_li = jQuery( target_li ).parents( 'li' )[0];
	var list_items = this.ddelement.find( 'li' );
	for ( var x = 0; x < list_items.length; x++ ) if ( list_items[x] == target_li ) { new_selection = x; break }

	if ( new_selection != this.selectedIndex ) 
	{
		var image = this.options[x][2] ? this.options[x][2] : '';
		this.element.find( 'img' )[0].src = image;
	}

	// preform super select
	this.select(e);

	// go to product url
	window.location = this.options[x][3];
}


Epson.cloneBlock = function( element, event )
{
	jQuery( element ).bind( event, function(e)
	{
		var link = jQuery( this );
		var class_name = '.cb-name-' + link[0].className.match( /cb-block-([^\s]+)/ )[1];
		var limit = link[0].className.match( /cb-limit-([^\s]+)/ )[1];
		var fieldsets = jQuery( class_name ).length;
		var first_fieldset = jQuery( class_name + ':first' );
		var last_fieldset = jQuery( class_name + ':last' );

		if ( fieldsets < limit )
		{
			var clone = first_fieldset.clone( true );
		
			// fix field/label ids
			clone.find( 'input, textarea, .jsDropdown' ).each( function() { jQuery( this ).attr( 'id', jQuery( this ).attr( 'id' ) + fieldsets ) } );
			clone.find( 'label' ).each( function() { jQuery( this ).attr( 'for', jQuery( this ).attr( 'for' ) + fieldsets ) } );
		
			// fix dropdowns
			clone.find( '.jsDropdown' ).each( function(i)
			{
				new Epson.GenericDropdown( first_fieldset.find( '.jsDropdown:eq('+i+')' ).data( 'jDropdown' ).reset( this ) );
			} );

			// remove button if at limit
			if ( fieldsets == limit - 1 ) link.remove();

			// append clone
			clone.css( { height:0, overflow:'hidden', scrollTop:first_fieldset.height() } ).animate( { height:first_fieldset.height(), scrollTop:0 }, 300, 'swing' ).insertAfter( last_fieldset );
		}

		e.preventDefault();
	} );
}



Epson.ToolTip =
{
	open: function( top, left, text )
	{
		// destroy any existing tooltips
		jQuery( '#Container .genericTooltip' ).remove();

		// create tooltip
		var tooltip = jQuery( '<div class="genericTooltip"><div class="top"></div><div class="content"></div><div class="bottom"></div></div>' );
		if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) tooltip.css( { opacity:0 } );
		tooltip.find( '.content' ).html( text );
		jQuery( '#Container' ).append( tooltip );

		// position
		tooltip.css( { height:'auto' } );
		var height = tooltip.height();
		tooltip.css( { height:0 } );
		tooltip.css( { top:top + 'px', left:left + 'px' } );

		if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) setTimeout(function(){tooltip.animate( { top:top-height, height:height, opacity:1 }, 300, 'easeout' )},250);
		else setTimeout(function(){tooltip.animate( { top:top-height, height:height }, 300, 'easeout' )},250);
	},
	
	close: function(e)
	{
		if ( !jQuery.browser.msie || jQuery.browser.version > 7 ) jQuery( '#Container .genericTooltip' ).animate( { opacity:0 } ).queue( function() { jQuery( this ).remove() } );
		else jQuery( '#Container .genericTooltip' ).remove();
	}
}


Epson.Forms =
{
	setup: function()
	{
		Epson.Forms.ToolTips.setup();

		Epson.Forms.AutoGender.setup();

		// set up checkout stages selection
		if ( jQuery( 'form .toggleFieldsets' ).length ) Epson.Forms.CheckoutStages.setup();

		// set up hidden label fields
		jQuery( 'label.fl_info' ).each( Epson.Forms.InfoLabels.setup );
	},

	ToolTips:
	{
		setup: function()
		{
			jQuery( 'form .f_tooltip' ).each( function() 
			{
				if ( jQuery( this ).prev( '.f_tooltip_text' ).length )
				{
					jQuery( jQuery( this ).prev( '.f_tooltip_text' )[0] ).bind( 'mouseover', function()
					{
						var icon = jQuery( jQuery( this ).next( '.f_tooltip' )[0] );
						Epson.ToolTip.open( jQuery( this ).offset().top, jQuery( this ).offset().left-30, icon.html() );
					} ).bind( 'mouseout', Epson.ToolTip.close );

					jQuery( this ).css( { padding:0 } );
				}
				else
				{
					jQuery( this ).bind( 'mouseover', function()
					{
						Epson.ToolTip.open( jQuery( this ).offset().top, jQuery( this ).offset().left-30, jQuery( this ).html() );
					} ).bind( 'mouseout', Epson.ToolTip.close );
				}
			} );
		}
	},

	InfoLabels:
	{
		setup: function()
		{
			// get corresponding label
			var label = arguments[0] instanceof jQuery ? arguments[0] : jQuery( this );
			var input = label.parent().find( 'input[id=' + label.attr( 'for' ) + ']' );

			if ( label.length )
			{
				if ( input.val() == '' || input.val() == label.text() )
				{
					input.addClass( 'fl_info_text' );
					input.val( label.text() );
				}
				input.data( 'default', label.text() )
				input.bind( 'focus', Epson.Forms.InfoLabels.focus );
			}
		},

		focus: function(e)
		{
			// get corresponding label
			var input = jQuery( this );
			var label = input.parent().find( 'label.fl_info' );

			if ( label.text() == input.val() )
			{
				input.removeClass( 'fl_info_text' );
				input.val( '' );
			}
			input.unbind( 'focus' ).bind( 'blur', Epson.Forms.InfoLabels.blur );
		},

		blur: function(e)
		{
			// get corresponding label
			var input = jQuery( this );
			var label = input.parent().find( 'label.fl_info' );

			if ( input.val() == '' )
			{
				input.addClass( 'fl_info_text' );
				if ( input.val() == '' ) input.val( label.text() );
			}
			input.unbind( 'blur' ).bind( 'focus', Epson.Forms.InfoLabels.focus );
		}
	},

	HiddenTerms:
	{
		setup: function( link, field )
		{
			// hide the privacy policy
			var pp_height = field.parents( '.fi_content' ).height();
			if ( pp_height == 0) pp_height = 150;

			field.parents( '.formItem' ).css( { display:'none', height:0 } );

			// add privacy policy event
			link.bind( 'click', function(e)
			{
				var l = link; var f = field.parents( '.formItem' );
				if ( !f.hasClass( 'open' ) ) f.show().addClass( 'open' ).animate( { height:pp_height }, 300, 'swing', Epson.Forms.HiddenTerms.finish );
				else f.removeClass( 'open' ).animate( { height:0 }, 300, 'swing', function() { jQuery( this ).hide(); Epson.Forms.HiddenTerms.finish() } );

				e.preventDefault();
			} );
		},

		finish: function()
		{
			if ( Epson.UI.Popup.element ) Epson.UI.Popup.position();
		}
	},

	Reg:
	{
		setup: function()
		{
			jQuery( '#GuestUser' ).hide();
			jQuery( 'input[@name=mainSelection]' ).click( function()
			{
				if ( jQuery("input[@name=mainSelection]:checked").val() == 'RegUser' )
				{
					jQuery( '#GuestUser' ).hide();
					jQuery( '#RegUser' ).show();
				}
				else
				{
					jQuery( '#RegUser' ).hide();
					jQuery( '#GuestUser' ).show();
				}
			} );
		}
	},

	AutoGender:
	{
		gender:-1,
		setup: function()
		{
			var array =jQuery( 'form .autoGenderSelector' ); 
			jQuery( 'form .autoGenderSelector' ).each( function()
			{
				// bind event
				jQuery( this ).bind( 'change', Epson.Forms.AutoGender.change );

				// display if select had initial value
				Epson.Forms.AutoGender.change.call( this, { target:this } );
			} );
		},

		change: function(e)
		{
			var title = this.value;
			var gender = Epson.Forms.AutoGender.gender;
			var fields = jQuery( e.target ).parents( 'fieldset' ).find( '.autoGender' );
			var radios = fields.find( 'input' );
			if ( jQuery.inArray( title, Epson.Localisation.AutoGender.MAPPING[0] ) != -1 ) {
				gender = 0;
				var hideGenderForm = true;
			}
			else if ( jQuery.inArray( title, Epson.Localisation.AutoGender.MAPPING[1] ) != -1 ) {
				gender = 2;
				var hideGenderForm = true;
			}
			if ( gender != -1 || !title )
			{
				if (hideGenderForm || !title) {
					fields.css( { opacity:1 } ).animate( { opacity:0 }, 300, 'swing', function() { jQuery( this ).hide() } );
				} else {
					fields.css( { opacity:0 } ).show().animate( { opacity:1 }, 300, 'swing' );
					radios[ gender ].checked = 'checked';
				}
				
			}
			else
			{
				fields.css( { opacity:0 } ).show().animate( { opacity:1 }, 300, 'swing' );
				if( radios.length > 0)
					radios[ 0 ].checked = 'checked';
				if ( eval( "typeof " + Epson.GenderValidate + " == 'function'" ) )	Epson.GenderValidate();
			}
		}
	},

	CheckoutStages:
	{
		setup: function()
		{
			//setup terms and conditions
			jQuery( 'form .toggleFieldsets' ).show();
			Epson.Forms.HiddenTerms.setup( jQuery( '#TermsConditions' ), jQuery( '#f_terms_conditions' ) );	
			if ( jQuery('#TermsConditionsUserReg').length ) Epson.Forms.HiddenTerms.setup( jQuery( '#TermsConditionsUserReg' ), jQuery( '#f_terms_conditions_userreg' ) );	
			
			// hide all fieldsets
			jQuery( 'form .toggleFieldsets' ).hide();
	
			// get current fieldset
			var fieldset = 0;
			jQuery( 'form .toggleFieldsetsSelector input[type=radio]' ).each( function( i ) { if ( this.checked ) fieldset = i } );
	
			// display current fieldset
			jQuery( jQuery( 'form .toggleFieldsets' )[ fieldset ] ).addClass( 'open' ).show();
	
			// bind events to radios
			jQuery( 'form .toggleFieldsetsSelector input[type=radio]' ).bind( 'click', function()
			{			
				var fieldset = 0;
				jQuery( 'form .toggleFieldsetsSelector input[type=radio]' ).each( function( i ) { if ( this.checked ) fieldset = i } );
				
				// hide old fieldset
				if ( jQuery( 'form .toggleFieldsets' )[ fieldset ] != jQuery( 'form .toggleFieldsets.open' )[0] ) jQuery( 'form .toggleFieldsets.open' ).removeClass( 'open' ).hide();
	
				// show new fieldset
				jQuery( jQuery( 'form .toggleFieldsets' )[ fieldset ] ).addClass( 'open' ).fadeIn();
			} );

				
			
			// bind events to dropdowns
			jQuery( 'form .toggleFieldsetsSelector .jsDropdown' ).bind( 'change', function()
			{
				for ( var i=0 ; i<this.options.length - 1 ;i++ )
				{
					if (this.value == i)
					{
						// hide old fieldset
						if ( jQuery( 'form .toggleFieldsets' )[i] != jQuery( 'form .toggleFieldsets.open' )[0] ) jQuery( 'form .toggleFieldsets.open' ).removeClass( 'open' ).hide();
						
						// show new fieldset
						jQuery( jQuery( 'form .toggleFieldsets' )[i] ).addClass( 'open' ).fadeIn();

						if ((('form .toggleFieldsetsInnerSelector').length) && (i==0) )
						{
							jQuery('form .toggleFieldsetsInner:first-child').css('display','');
						}
					}
				}
			} );

			

			jQuery( 'form .toggleFieldsetsInnerSelector .jsDropdown' ).bind( 'change', function()
			{
				
				for ( var i=0 ; i<this.options.length - 1 ;i++ )
				{
					if (this.value == i)
					{
						// hide old fieldset
						if ( jQuery( 'form .toggleFieldsetsInner' )[i] != jQuery( 'form .toggleFieldsetsInner.open' )[0] ) jQuery( 'form .toggleFieldsetsInner.open' ).removeClass( 'open' ).hide();
						
						// show new fieldset
						jQuery( jQuery( 'form .toggleFieldsetsInner' )[i] ).addClass( 'open' ).fadeIn();
					}
				}
			} );
		}
	},

	displayError: function( valid, input, message )
	{
		message = escape(message);
		var form_item = jQuery( jQuery( input )[0] ).parents( '.formItem' );

		if ( jQuery('.warrantyIntro').length && jQuery('.productRegDetails').length) form_item = jQuery( jQuery( input )[0] ).parent( 'div' );

		if ( !form_item.length ) form_item = jQuery( jQuery( input )[0] ).parents( 'form' );
		var errors = escape(form_item.find( '.f_error_text' ).text());		
		if ( !valid )
		{
			if ( !errors.match( message ) )
			{
				form_item.addClass( 'f_error' ).prepend( jQuery( '<div class="f_error_text" id="generalError.'+unescape(message)+'"><strong>'+unescape(message)+'</strong></div>' ) );

				var height = form_item.find( '.f_error_text' ).height();

				form_item.find( '.f_error_text' ).css( { height:0, visibility:'', minHeight:0 } ).animate( { height:height }, 300, 'swing', function() { jQuery( this ).css( { minHeight:'' } ) } );
        		var tlExceptionEvent = new TeaLeaf.Event("INFO", "EXCEPTION");
        		var tlExceptionEventArray = new Array(
             	   "Class", "f_error_text",
              	   "Id", "generalError "+unescape(message));
       			tlExceptionEvent.tlAddData(tlExceptionEventArray);
        		tlExceptionEvent.tlSend();
			}
		}
		else
		{
			form_item.find( '.f_error_text' ).animate( { height:0 }, 300, 'swing', function(){ form_item.removeClass( 'f_error' ); form_item.find( '.f_error_text' ).remove() } );
		}
	}
}

/* Expandable List */
Epson.GenericExpandToggle = function()
{
	jQuery( this ).bind( 'click', function(e)
	{
		jQuery( this ).parent().find( 'ul li.hidden' ).each( function() { jQuery( this ).toggle() } );
		if ( jQuery( this ).hasClass( 'buttonPlus' ) ) jQuery( this ).removeClass( 'buttonPlus' ).addClass( 'buttonMinus' ).find( 'span' ).text( Epson.Localisation.ExpandableList.TXT001 );
		else jQuery( this ).removeClass( 'buttonMinus' ).addClass( 'buttonPlus' ).find( 'span' ).text( Epson.Localisation.ExpandableList.TXT002 );
		e.preventDefault()
	} );
}


/* Generic Comparison Collapsible Module */
Epson.CollapsableModule = function ( header, content )
{
	jQuery( header ).bind( 'click', function()
	{
		jQuery( content ).slideToggle();
		jQuery( this ).toggleClass( 'open' );				
	} );

	if ( jQuery( content ).find('#TermsConditions').length ) Epson.Forms.HiddenTerms.setup( jQuery( '#TermsConditions' ), jQuery( '#f_terms_conditions' ) );
}


Epson.UI =
{
	Popup:
	{
		element:null,
		positions:null,
		dimensions:null,

		load: function( url, callback )
		{
			// display loader
			Epson.UI.Popup.Loader.display();

			// ajax load of a url
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).load( url, null, function()
			{
				Epson.UI.Popup.Loader.hide();
				
				// set up generic functionality
				jQuery( '#Popup .triggerPopup' ).each( function() { jQuery( this ).bind( 'click', Epson.UI.Popup.loadGeneric ) } );

				// set up custom close buttons
				Epson.UI.Popup.element.find( '.closePopup' ).bind( 'click', Epson.UI.Popup.close );

				// set up tooltips
				Epson.Forms.ToolTips.setup();

				// set up dropdowns
				jQuery( '#Popup select.jsDropdown' ).each( function() { new Epson.GenericDropdown( this ) } );

				callback();
			} );
		},

		loadGeneric: function(e)
		{
			var trigger = this;
			var title = this.className.match( /tp-title-([^\s]+)/ );
			var url = this.className.match( /tp-url-([^\s]+)/ );
			var callback = this.className.match( /tp-callback-([^\s]+)/ );

			if ( title ) title = decodeURI( title[1] );

			if ( url )
			{
				Epson.UI.Popup.open( title );
				Epson.UI.Popup.load( url[1], function()
				{
					if ( callback ) eval( callback[1] + '( trigger )' );

					Epson.UI.Popup.position();
				} );
			}

			e.preventDefault();
		},

		open: function( title )
		{
			if ( !jQuery( '#Popup' ).length )
			{
				// render popup
				Epson.UI.Popup.element = jQuery( '<div id="Popup" class="genericRoundedCorners genericPopup"><div class="header"><div class="headerContent"><p>' + title + '</p><div class="closeButton"><a href="#" class="buttonBlueClose"><span>close</span></a></div></div></div><div class="content clear"></div><div class="bottom"><div class="bl"></div><div class="br"></div><div class="b"></div></div>	</div>' );	
				Epson.UI.Popup.element.find( '.closeButton a' ).bind( 'click', Epson.UI.Popup.close );
				jQuery ( '#Container' ).append( Epson.UI.Popup.element );

				// render backdrop
				jQuery ( '#Container' ).append( jQuery( '<div id="PopupBackground"></div>' ).css( { width:jQuery( window ).width()+'px', height:jQuery( window ).height()+'px' } ) );
				if ( jQuery.browser.msie && parseInt( jQuery.browser.version ) == 6 ) jQuery( window ).bind( 'scroll', function() { Epson.UI.Popup.position(); jQuery( '#PopupBackground' ).css( { top:document.documentElement.scrollTop+'px' } ) } );

				// set up window resize event to reposition popup
				jQuery( window ).bind( 'resize', Epson.UI.Popup.position );
			}
			else jQuery( '#Popup .header p' ).text( title );
		},

		position: function()
		{
			var inited = Epson.UI.Popup.positions;

			Epson.UI.Popup.positions = ( jQuery( window ).height() / 2 ) - ( Epson.UI.Popup.element.height() / 2 );
			if ( jQuery.browser.msie && parseInt( jQuery.browser.version ) == 6 ) Epson.UI.Popup.positions += document.documentElement.scrollTop;

			if ( inited ) Epson.UI.Popup.element.stop().animate( { top:Epson.UI.Popup.positions }, 500, 'swing' );
			else Epson.UI.Popup.element.css( { top:Epson.UI.Popup.positions+'px' } );

			// ensure backdrop is still right dimensions
			jQuery ( '#PopupBackground' ).css( { width:jQuery( window ).width()+'px', height:jQuery( window ).height()+'px' } );
		},

		populate: function( content )
		{
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).append( content );
		},

		clear: function()
		{
			Epson.UI.Popup.element.find( '.content' ).empty();
		},

		dimension: function( callback )
		{
			if ( !arguments.length ) var callback = function() { };

			// save old dimensions
			var old_height = jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).height();

			// reset element to get new dimensions
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).css( { height:'' } );

			// get new dimensions
			var height = jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).height();

			// set old dimensions again		
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).css( { height:old_height+'px' } );

			// position popup if necessary
			if ( Epson.UI.Popup.positions )
			{
				var top = Epson.UI.Popup.element.offset().top - jQuery( window ).scrollTop() - ( ( height - old_height ) / 2 );

				Epson.UI.Popup.element.animate( { top:top }, 500, 'swing' );
			}
			else
			{
				var top = ( jQuery( window ).height() / 2 ) - ( Epson.UI.Popup.element.height() / 2 );
				Epson.UI.Popup.element.css( { top:top+'px' } );
			}

			// animate resize
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).animate( { height:height }, 500, 'swing', callback );

			// save the position of the popup
			Epson.UI.Popup.positions = top;
		},

		undimension: function()
		{
			jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).css( { height:'' } );
		},

		addButton: function( name, event )
		{
			if ( !Epson.UI.Popup.element.find( '.headerContent' ).text().match( name ) )
			{
				Epson.UI.Popup.element.find( '.headerContent' ).prepend ( jQuery( '<div class="backButton"><a href="#" class="buttonSmall"><span>' + name + '</span></a></a></div> ' ).find( 'a' ).bind( 'click', event ).parent() );
			}
		},

		addNormalButton: function( name, event )
		{
			if ( !Epson.UI.Popup.element.find( '.headerContent' ).text().match( name ) )
			{
				if ( Epson.UI.Popup.element.find( '.headerContent .normalButtons' ).length ) Epson.UI.Popup.element.find( '.headerContent .normalButtons' ).append( jQuery( '<a href="#" class="buttonSmall"><span>' + name + '</span></a>' ).bind( 'click', event ) );
				else Epson.UI.Popup.element.find( '.headerContent' ).append ( jQuery( '<div class="normalButtons"><a href="#" class="buttonSmall"><span>' + name + '</span></a></div> ' ).find( 'a' ).bind( 'click', event ).parent() );
			}
		},

		removeButton: function()
		{
			Epson.UI.Popup.element.find( '.header .backButton, .header .normalButtons' ).remove();
		},

		close: function(e)
		{
			// remove popup
			Epson.UI.Popup.element.remove();
			Epson.UI.Popup.element = null;
			Epson.UI.Popup.positions = null;
			Epson.UI.Popup.dimensions = null;

			// remove backdrop
			jQuery( '#PopupBackground' ).remove();

			// remove window resize event to reposition popup
			jQuery( window ).unbind( 'resize', Epson.UI.Popup.position );

			if (jQuery.browser.msie) if (e) e.preventDefault();	
			//else  if ( e.preventDefault() ) e.preventDefault();
		},

		Loader:
		{
			display: function()
			{
				jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).addClass( 'genericPopupLoader' );
			},

			hide: function()
			{
				jQuery( Epson.UI.Popup.element.find( '.content' )[0] ).removeClass( 'genericPopupLoader' );
			}
		}
	}
}


Epson.Authentication =
{
	setupSendPassword: function()
	{
		jQuery( '#Popup form' ).bind( 'submit', Epson.Authentication.sendPassword );
	},

	sendPassword: function(e) 
	{
		if ( validation_retrieve.validateForm() )
		{
			var url = jQuery( this ).attr( 'action' );
			var data = url.match( /\?/ ) ? '&' : '?';
			jQuery( this ).find( 'input[@type=text],input[@type=password],input[@type=hidden],.jsDropdown' ).each( function() { data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val() + '&' } );
			jQuery( this ).find( 'input[@type=radio],input[@type=checkbox]' ).each( function() { if ( this.checked ) data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val() + '&' } );
			data.substr( 0, data.length - 1 );

			// send off authentication
			Epson.UI.Popup.load( url+data, function(){} );
		}

		e.preventDefault();
	}
}


Epson.Email =
{
	setup: function()
	{
		jQuery( '#Popup form' ).bind( 'submit', Epson.Email.send );
	},

	send: function(e)
	{
		if ( validation_email.validateForm() )
		{
			var url = jQuery(this).attr('class').match( /email-url-([^\s]+)/ );
			if ( url ) url = url[1];
			var data = url.match( /\?/ ) ? '&' : '?';
			jQuery( this ).find( 'input[@type=text],input[@type=password],input[@type=hidden],.jsDropdown' ).each( function() { data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val().replace( /^\s+$/, '' ) + '&' } );
			jQuery( this ).find( 'input[@type=radio],input[@type=checkbox]' ).each( function() { if ( this.checked ) data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val().replace( /^\s+$/, '' ) + '&' } );
			jQuery( this ).find('textarea').each( function() { data += jQuery( this ).attr( 'name' ) + '=' + escape(jQuery(this).val())});
			data.substr( 0, data.length - 1 );
	
			// send off authentication
			Epson.UI.Popup.load( url+data, function(){} );
		}

		e.preventDefault();
	}
}

Epson.Download =
{
	Validation:{},

	setup: function()
	{
		// set up hidden terms
		Epson.Forms.HiddenTerms.setup( jQuery( '#PrivacyPolicy' ), jQuery( '#f_dl_privacypolicy' ) );
		Epson.Forms.HiddenTerms.setup( jQuery( '#LicenseAgreement' ), jQuery( '#f_dl_licenseagreement' ) );

		// set up events
		jQuery( '#DownloadForm' ).bind( 'submit', Epson.Download.send );
		jQuery( '#DownloadForm a.button.close' ).bind( 'click', Epson.UI.Popup.close );					
	},
	setPopup: function()
	{
		
		if (!jQuery.cookie('userEmailId')) jQuery('.buttonDownload').each(function(){jQuery(this).bind( 'click', Epson.UI.Popup.loadGeneric )}) 
		else jQuery('.buttonDownload').each(function(){ jQuery(this).unbind( 'click', Epson.UI.Popup.loadGeneric )}); 		
	},
	send: function(e)
	{
		if ( Epson.Download.Validation.validateForm() ) 
		{
			setTimeout( Epson.UI.Popup.close, 100 );
			if ((jQuery('#f_dl_email').val().replace( /^\s+$/, '' ) != '') && (jQuery('#f_dl_privacy').attr('checked') ) ) jQuery('.buttonDownload').each(function()
			{ 
				jQuery(this).unbind( 'click', Epson.UI.Popup.loadGeneric )								
			}); 
		}
		else e.preventDefault();			
	}

}

Epson.Newsletter =
{
	Validation:{},
	url:'',
	title:'',
	pp_height:0,

	setup: function()
	{
		Epson.Newsletter.url = jQuery( '#NewsletterSignup' ).attr( 'action' ).split("?")[0];
		Epson.Newsletter.title = jQuery( '#NewsletterSignup' ).parent().find( 'h3' ).text();

		// set up events
		jQuery( '#NewsletterSignup' ).bind( 'submit', Epson.Newsletter.popup );
	},

	popup: function(e)
	{
		if ( Epson.Newsletter.Validation.initial.validateForm() )
		{
			Epson.UI.Popup.open( Epson.Newsletter.title );
			Epson.Newsletter.url = Epson.Newsletter.url.split("?")[0] + "?email=" + jQuery( '#f_newsletter_email' ).val();
			Epson.UI.Popup.load( Epson.Newsletter.url, Epson.Newsletter.setupPopup );
		}

		e.preventDefault();
	},

	setupPopup: function()
	{
		// prepopulate email address
		jQuery( '#Popup #f_m_newsletter_email' ).val( jQuery( '#f_newsletter_email' ).val() );

		// set up hidden privacy policy
		Epson.Forms.HiddenTerms.setup( jQuery( '#PrivacyPolicy' ), jQuery( '#f_m_newsletter_privacypolicy' ) );

		// position popup
		Epson.UI.Popup.position();

		// add event to submit
		jQuery( '#Popup form' ).bind( 'submit', Epson.Newsletter.send );
	},	

	send: function(e)
	{
		if ( Epson.Newsletter.Validation.main.validateForm() )
		{
			var url = this.className.match( /nl-url-([^\s]+)/ );
			if (url) url = url[1];
			var data = url.match( /\?/ ) ? '&' : '?';
			jQuery( this ).find( 'input[@type=text],input[@type=password],input[@type=hidden],.jsDropdown' ).each( function() { data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val().replace( /^\s+$/, '' ) + '&' } );
			jQuery( this ).find( 'input[@type=radio],input[@type=checkbox]' ).each( function() { if ( this.checked ) data += jQuery( this ).attr( 'name' ) + '=' + jQuery( this ).val().replace( /^\s+$/, '' ) + '&' } );
			data.substr( 0, data.length - 1 );
			
			// send off authentication
			Epson.UI.Popup.load( url+data, function(){} );
		}

		e.preventDefault();
	}
}


Epson.UnRegisterProduct = function( element )
{
	var _element = element;
	var _url = '';
	var _content;

	function setup()
	{
		_url = _element.className.match( /nmp-url-([^\s]+)/ );

		if ( _url )
		{
			_url = _url[1];

			jQuery( _element ).bind( 'click', confirm );
		}
	}

	function confirm(e)
	{
		_content = jQuery( '<div id="UnRegisterConfirmation" class="alertNotificationPopup"><div class="alertNotificationPopupContent"><div class="top"></div><div class="content"><h4>' + Epson.Localisation.UnRegisterProduct.TXT001 + '</h4><a href="' + _url + '" class="buttonBlue"><span>' + Epson.Localisation.UnRegisterProduct.TXT002 + '</span></a> <a href="#" class="button closeNotification"><span>' + Epson.Localisation.UnRegisterProduct.TXT003 + '</span></a></div><div class="bottom"></div></div></div>' );
		jQuery( '#Container' ).append( _content );

		// position and animate notification
		var position = jQuery( _element ).offset();
		_content.css( { top:position.top-_content.height()+'px', left:position.left+'px', opacity:0 } );
		_content.animate( { opacity:1 }, 300, 'swing' );

		// bind close event
		_content.find( '.closeNotification' ).bind( 'click', close );
		_content.bind( 'click', function(e) { e.stopPropagation() } );
		setTimeout( function() { jQuery( 'body' ).bind( 'click', close ) }, 1 );

		e.preventDefault();
	}

	function close(e)
	{
		jQuery( '#UnRegisterConfirmation' ).remove();
		jQuery( 'body' ).unbind( 'click', close )

		e.preventDefault();
	}

	setup();
}


Epson.Cookies =
{
	name:'EpsonShop',

	read: function( property )
	{
		var cookie = jQuery.cookie( Epson.Cookies.name );

		if ( cookie ) cookie = jQuery.parseJSON( cookie );
		else return null;

		if ( cookie[ property] ) return cookie[ property];
		else return null;
	},
	
	write: function( property, value )
	{
		var cookie = jQuery.cookie( Epson.Cookies.name );

		if ( cookie ) cookie = jQuery.parseJSON( cookie );
		else cookie = {  };

		cookie[ property ] = value;

		jQuery.cookie( Epson.Cookies.name, jQuery.toJSON( cookie ), { expires:30, path:'/' } );
	},

	remove: function( property )
	{
		var cookie = jQuery.cookie( Epson.Cookies.name );

		if ( cookie ) cookie = jQuery.parseJSON( cookie );
		else cookie = {  };

		if ( cookie[ property ] ) delete cookie[ property ];

		cookie = jQuery.toJSON( cookie );
		if ( cookie == '{}' ) cookie = null;

		jQuery.cookie( Epson.Cookies.name, cookie, { expires:30, path:'/' } );
	}
}
