	$(document).ready(function() { 		
		
		$('.top').click(function(){
			$.scrollTo(0);
			return false;
		});

		$('a.lightbox').lightBox({
			imageLoading: 'themes/eurowalls/images/lightbox-ico-loading.gif',
			imageBtnClose: 'themes/eurowalls/images/lightbox-btn-close.gif',
			imageBtnPrev: 'themes/eurowalls/images/lightbox-btn-prev.gif',
			imageBtnNext: 'themes/eurowalls/images/lightbox-btn-next.gif'
		});
		
		swapValue = [];
		$("#Search input").each(function(i){
		   swapValue[i] = $(this).val();
		   $(this).focus(function(){
			  if ($(this).val() == swapValue[i]) {
				 $(this).val("");
			  }
			  $(this).addClass("focus");
		   }).blur(function(){
			  if ($.trim($(this).val()) == "") {
				 $(this).val(swapValue[i]);
			 $(this).removeClass("focus");
			  }
		   });
		});
		
		$('.external').click(function(){
			window.open(this.href);
			return false;
		});

		$("#Form_PaymentForm").submit( function () {
		  	$(".Actions").hide();
		  	$("#submitting").show();
		});
				
		$('.home-gallery').cycle({ 
		    fx:     'scrollHorz', 
		    speed:  1500, 
		    timeout: 7000, 
		    next:   '.home-gallery-controls-beta a', 
		    prev:   '.home-gallery-controls-alpha a'
		});
		
		$('.gallery-images').cycle({ 
		    fx:     'fade', 
		    speed:  'slow', 
		    timeout: 7000, 
		    next:   '.gallery-controls-beta a', 
		    prev:   '.gallery-controls-alpha a' 
		});

		
		$('.portfolio-gallery-images').cycle({ 
		    fx:     'fade', 
		    speed:  'slow', 
		    timeout: 7000, 
		    next:   '.portfolio-gallery-controls a#next', 
		    prev:   '.portfolio-gallery-controls a#prev' 
		});
		
		$('#product-gallery-thumbs-inner a').click(function(){
           $('#product-gallery-large img').remove();
           $('#loading').show();
            var href = $(this).attr('href')
            var img = new Image();
            $(img).load(function(){
                $('#product-gallery-large').append(img);
                $('#loading').hide();
            }).attr('src',href);
            
            var OrginalString = $(this).attr('class');
            
            var SplitString = OrginalString.split("-");
			
            $("#add-to-cart #Style select option[value='"+SplitString[1]+"']").attr("selected", "selected");
            
            return false;
        });	

		$("#add-to-cart #Style select").change(function () {
			var OptionString = "";
			$("#add-to-cart #Style select option:selected").each(function () {
			    OptionString = 'option-'+$(this).val();
			});
			
			$.galleriffic.gotoImage(OptionString);
		 });

		$('#commercial-gallery-thumbs a').click(function(){
           $('#commercial-gallery-large img').remove();
           $('#loading').show();
            var href = $(this).attr('href')
            var img = new Image();
            $(img).load(function(){
                $('#commercial-gallery-large').append(img);
                $('#loading').hide();
            }).attr('src',href);
            
            var OrginalString = $(this).attr('class');
            
            var SplitString = OrginalString.split("-");
			
            $("#add-to-cart-commercial #Style select option[value='"+SplitString[1]+"']").attr("selected", "selected");
            
            return false;
        });

		$("#add-to-cart-commercial #Style select").change(function () {
			var OptionString = "";
			$("#add-to-cart-commercial #Style select option:selected").each(function () {
			    OptionString = 'option-'+$(this).val();
			});
			
			$("a."+OptionString).click();
		});

		var onMouseOutOpacity = 1;
		$('#thumbs ul.thumbs li, div.navigation a.pageLink').opacityrollover({
			mouseOutOpacity:   onMouseOutOpacity,
			mouseOverOpacity:  1.0,
			fadeSpeed:         'fast',
			exemptionSelector: '.selected'
		});
		
		// Initialize Advanced Galleriffic Gallery
		var gallery = $('#thumbs').galleriffic({
			delay:                     1500,
			numThumbs:                 8,
			preloadAhead:              -1,
			enableTopPager:            false,
			enableBottomPager:         false,
			imageContainerSel:         '#slideshow',
			controlsContainerSel:      '#controls',
			captionContainerSel:       '#caption',
			loadingContainerSel:       '#loading',
			renderSSControls:          true,
			renderNavControls:         true,
			playLinkText:              'Play Slideshow',
			pauseLinkText:             'Pause Slideshow',
			prevLinkText:              '&lsaquo; Previous Photo',
			nextLinkText:              'Next Photo &rsaquo;',
			nextPageLinkText:          'Next &rsaquo;',
			prevPageLinkText:          '&lsaquo; Prev',
			enableHistory:             true,
			autoStart:                 true,
			syncTransitions:           true,
			defaultTransitionDuration: 900,
	onSlideChangeOut:             function(prevIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity);
					},
					onSlideChangeIn: function(nextIndex) {
						this.find('ul.thumbs').children().eq(nextIndex).fadeTo('fast', 1.0);
						SelectValue = this.find('ul.thumbs').children().eq(nextIndex).find('img').attr('alt');
				       	$("#Style select option[value='"+SelectValue+"']").attr("selected", "selected");
					},
					/*
			onSlideChange:
			function(prevIndex, nextIndex) {
				this.find('ul.thumbs').children().eq(prevIndex).fadeTo('fast', onMouseOutOpacity);
				this.find('ul.thumbs').children().eq(nextIndex).fadeTo('fast', 1.0);
					

				SelectValue = this.find('ul.thumbs').children().eq(nextIndex).find('img').attr('alt');
				
            	$("#Style select option[value='"+SelectValue+"']").attr("selected", "selected");

			},*/
			onPageTransitionOut:       function(callback) {
				
				this.fadeTo('fast', 0.0, callback);
			},
			onPageTransitionIn:        function() {



				var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
				var nextPageLink = this.find('a.next').css('visibility', 'hidden');
				
				if (this.displayedPage > 0)
					prevPageLink.css('visibility', 'visible');

				var lastPage = this.getNumPages() - 1;
				if (this.displayedPage < lastPage)
					nextPageLink.css('visibility', 'visible');

				this.fadeTo('fast', 1.0);
			}
		});

		gallery.find('a.prev').click(function(e) {
			gallery.previousPage();
			e.preventDefault();
		});

		gallery.find('a.next').click(function(e) {
			gallery.nextPage();
			e.preventDefault();
		});

		function pageload(hash) {
			if(hash) {
				$.galleriffic.gotoImage(hash);
			} else {
				gallery.gotoIndex(1);
			}
		}

		$.history.init(pageload);
		
		$("a[rel='history']").live('click', function(e) {
			if (e.button != 0) return true;

			var hash = this.href;
			hash = hash.replace(/^.*#/, '');

			$.history.load(hash);

			return false;
		});

		pageload();

	});

				
