jQuery(document).ready(function() {								
	
	jQuery('#MastHead a.mastheadCheckout').remove();
	jQuery('#MastHead .mastheadCheckout span').remove();
	
	jQuery('#UserLinks li#selCountryDropdown').remove();
	
	var ireLink;
	ireLink = jQuery('<li>Ireland</li>');
	jQuery('#UserLinks ul').append(ireLink);
	
	jQuery('#MastHead .primaryNavigation ul li').remove();
	
	var topNav;
	topNav = jQuery('<li><strong><a href="http://www.epson.co.uk/en" title="Products">Products</a></strong></li><li><a href="http://www.epson.co.uk/Support" title="Support">Support</a></li><li><a href="http://www.epson.co.uk/Explore-Epson" title="Explore Epson">Explore Epson</a></li><li class="last"><a href="http://www.epson.co.uk/My-Epson" title="My Epson">My Epson</a></li>');
	jQuery('#MastHead .primaryNavigation ul').append(topNav);
	
	var subNav;
	subNav = jQuery('<li class="dropdown"><a id="categoryDrop" title="All Products" href="#">All Products</a><ul><li><a href="http://www.epson.co.uk/Printers-and-All-In-Ones">Printers and All-In-Ones</a></li><li><a href="http://www.epson.co.uk/Scanners">Scanners</a></li><li><a href="http://www.epson.co.uk/Projectors">Projectors</a></li><li><a href="http://www.epson.co.uk/Discproducer">Discproducer</a></li><li><a href="http://www.epson.co.uk/Media-Storage-Viewers">Media Storage Viewers</a></li></ul></li><li><a href="http://www.epson.co.uk/Store/Ink-Supplies">Ink & Supplies</a></li>');
	jQuery('#MastHead .secondaryNavigation ul').append(subNav);
	
});

Epson.Carousel = {
    assets_url: '',
    teasers: [],

    setup: function() {
        var swf = "http://www.epson.co.uk/assets/flash/carousel.swf";
        var config = "http://www.epson.co.uk/assets/flash/xml/carousel2d.xml";
        var data = "http://assets.epson-europe.com/ie/xigenCarouselData.xml";
        var panel = "home";
        var alt_content_url = "http://www.epson.co.uk";
        //Epson.Carousel.assets_url = jQuery('#FlashCarousel')[0].className.match(/fc-assets-([^\s]+)/);

        if (panel) panel = panel;
        if (!swf || !config || !data) return;

        var flashvars = {
            carouselDataXmlPath: config,
            panelDataXmlPath: data
        };

        // if the page has a pre-defined item, set it
        var anchor = window.location && window.location.toString().match(/#([a-zA-Z]+)$/);
        if (anchor) anchor = anchor;
        flashvars.panelName = panel || anchor;

        // write in flash module or pull in static content if no flash
        if (swfobject.getFlashPlayerVersion().major > 0) swfobject.embedSWF(swf, 'FlashCarousel', 940, 400, '9.0.28', false, flashvars, {
            wmode: 'transparent'
        });
        else {
            var content = jQuery('#FlashCarousel').html().replace(/<\/?noscript>/ig, '');
            if (content != '') jQuery('#FlashCarousel').empty().append(content);
            else jQuery('#FlashCarousel').load(alt_content_url);
        }

        // load in correct teaser
        if (anchor) Epson.Carousel.loadTeasers(anchor, 0);
    },

    setupTracking: function() {
        // set up TeaLeaf tracking for Flash on window unload
        jQuery(window).bind('beforeunload', jQuery('#FlashCarousel').tlFlushXML);
        jQuery(window).bind('unload', jQuery('#FlashCarousel').tlFlushXML);
    },

    loadTeasers: function(item, direction) {
        var teasers = Epson.Carousel.teasers[item];

        if (teasers) {
            // set up scrolling dimensions
            jQuery('#Teasers').css({
                overflow: 'hidden',
                position: 'relative'
            }).find('ul').css({
                width: '1880px'
            });

            var x = direction ? 0: 2;
            while (true) {
                var teaser;

                if (teasers[x].type == 0) {
                    teaser = jQuery('<li class="type0"><h4><a href="' + teasers[x].link + '">' + teasers[x].title + '</a></h4><p>' + teasers[x].description + '</p><a href="' + teasers[x].link + '"><img src="' + teasers[x].image + '" /></a></li>');
                } else if (teasers[x].type == 1) {
                    teaser = jQuery('<li class="type1"><h4><a href="' + teasers[x].link + '">' + teasers[x].title + '</a></h4><p>' + teasers[x].description + '</p><a href="' + teasers[x].link + '"><img src="' + teasers[x].image + '" /></a></li>');
                } else if (teasers[x].type == 2) {
                    teaser = jQuery('<li class="type2"><a href="' + teasers[x].link + '"><img src="' + teasers[x].image + '" /></a></li>');
                }

                if (direction) {
                    jQuery('#Teasers ul').append(teaser);
                    if (++x > 2) break;
                } else {
                    jQuery('#Teasers ul').prepend(teaser);
                    jQuery('#Teasers .content').css({
                        marginLeft: parseInt(jQuery('#Teasers .content').css('marginLeft')) - 314 + 'px'
                    });
                    if (--x < 0) break;
                }
            }

            // animate new teasers in
            if (direction) {
                jQuery('#Teasers .content').animate({
                    marginLeft: -940
                },
                750, 'swing',
                function() {
                    for (var x = 0; x < 3; x++) {
                        jQuery('#Teasers ul li:first').remove();
                        jQuery('#Teasers .content').css({
                            marginLeft: parseInt(jQuery('#Teasers .content').css('marginLeft')) + 314 + 'px'
                        })
                    };
                    jQuery('#Teasers .content').css({
                        marginLeft: ''
                    });
                    jQuery('#Teasers').css({
                        overflow: ''
                    }).find('ul').css({
                        width: ''
                    })
                });

                jQuery('#Teasers ul li:nth(3)').append(jQuery('<div class="wc_tl"></div><div class="wc_bl"></div>'));
                jQuery('#Teasers ul li:last').append(jQuery('<div class="wc_tr"></div><div class="wc_br"></div>'));

            } else {
                jQuery('#Teasers .content').animate({
                    marginLeft: 0
                },
                750, 'swing',
                function() {
                    for (var x = 0; x < 3; x++) {
                        jQuery('#Teasers ul li:last').remove();
                    };
                    jQuery('#Teasers .content').css({
                        marginLeft: ''
                    });
                    jQuery('#Teasers').css({
                        overflow: ''
                    }).find('ul').css({
                        width: ''
                    })
                });

                jQuery('#Teasers ul li:first').append(jQuery('<div class="wc_tl"></div><div class="wc_bl"></div>'));
                jQuery('#Teasers ul li:nth(2)').append(jQuery('<div class="wc_tr"></div><div class="wc_br"></div>'));
            }

            // update position in window location
            //			window.location = window.location.toString().match( /^([^#]+)/ )[1] + '#' + item;
        }
    }

    /*cacheAssets: function() {
        if (Epson.Carousel.assets_url) jQuery.getJSON(Epson.Carousel.assets_url[1], null,
        function(json) {
            var path = json.path || '';
            if (json.css) jQuery.each(json.css,
            function() {
                jQuery.ajax({
                    url: path + 'css/' + this,
                    cache: true,
                    dataType: 'text',
                    type: 'GET'
                })
            });
            if (json.js) jQuery.each(json.js,
            function() {
                jQuery.ajax({
                    url: path + 'js/' + this,
                    cache: true,
                    dataType: 'text',
                    type: 'GET'
                })
            });
        });
    }*/
}
jQuery(document).ready(Epson.Carousel.setup);

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"><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);
    }
}

jQuery(document).ready(function() {								
    jQuery('#MastHead .secondaryNavigation .dropdown').each(function() {
        new Epson.SecondaryNavDropdowns(this)
    })
});

	var homeArray = new Array();
	var sohoArray = new Array();
	var businessArray = new Array();
	var retailArray = new Array();
	var largeEnterpriseArray = new Array();
	var graphicsArray = new Array();
	
	sohoArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/Explore-Epson/1223291673146',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1227920046777',
		alt: 'Preserving the Past - Restore, repair and revisit your precious photos.'
	});
	
	largeEnterpriseArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/Explore-Epson/1223288347518',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287941430',
		alt: 'T_FGN_ultraChrome_010209_UK'
	});
	
	businessArray.push({
		type: 1,
		title: 'Printer technology at a glance',
		description: 'Inkjet, thermal or impact? We help you decide.',
		link: 'http://www.epson.co.uk/Retail-Solutions',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287697186',
		alt: 'T FVCN retailPrinter 010209'
	});
	
	retailArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/Scanners',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1227912955993',
		alt: 'T FGN ViewOurRangeScanners 010709 UK'
	});
	
	graphicsArray.push({
		type: 0,
		title: 'See the light when scanning',
		description: 'Less power used with ReadyScan LED technology',
		link: 'http://www.epson.co.uk/Explore-Epson/1223291671476',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287657931',
		alt: 'T FHCN readyScan 010209'
	});
	
	sohoArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/Graphic-Arts/Pro-Photography/Printing',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223294164305',
		alt: 'Epson Photographic Print Media'
	});
	
	largeEnterpriseArray.push({
		type: 0,
		title: 'Maximum impact at the PoS',
		description: 'Posters and signage in stunning colour, on demand.',
		link: 'http://www.epson.co.uk/Graphic-Arts/Signage-and-POS',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287605850',
		alt: 'T FHCN GS6000 010209 UK'
	});
	
	businessArray.push({
		type: 1,
		title: 'Printer technology at a glance',
		description: 'Inkjet, thermal or impact? We help you decide.',
		link: 'http://www.epson.co.uk/Retail-Solutions',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287697186',
		alt: 'T FVCN retailPrinter 010209'
	});
	
	retailArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/store',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287941002',
		alt: 'T_FGN_projectors_010209_UK'
	});
	
	graphicsArray.push({
		type: 0,
		title: 'Epson Stylus Pro GS6000',
		description: 'The new standard in solvent printing',
		link: 'http://www.epson.co.uk/Printers-and-All-In-Ones/Large-Format/Epson-Stylus-Pro-GS6000',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287605850',
		alt: 'T FHCN GS6000 010209 UK'
	});
	
	sohoArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/free3yearwarranty/',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1227911847512',
		alt: 'Free 3 year unlimited on-site lamp warranty'
	});
	
	largeEnterpriseArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/uk',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1227920271222',
		alt: 'Digigraphie by Epson'
	});
	
	businessArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1227920034826',
		alt: 'myEpsonPrinter.eu'
	});
	
	retailArray.push({
		type: 2,
		link: 'http://www.epson.co.uk/Explore-Epson/1223288347518',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287941430',
		alt: 'T_FGN_ultraChrome_010209_UK'
	});
	
	graphicsArray.push({
		type: 0,
		title: 'Scanners to suit your needs.',
		description: 'Explore our range of A3 and A4 business scanners.',
		link: 'http://www.epson.co.uk/Scanners',
		image: 'http://www.epson.co.uk/cs/ContentServer?pagename=EpsonWTP/RenderBlob&TYPE=EpsonImage&OBJECTID=1223287608054',
		alt: 'T FHCN GT1500 010209 UK'
	});
	
	Epson.Carousel.teasers = {


		home: sohoArray,
		arts: graphicsArray,
		retail: retailArray,
		business: businessArray,
		public: largeEnterpriseArray
	};
