	
	/* Home made home page gallery for Highland Park Village */
	/* ----------------------------------------------------- */
	
	/* 	Edits 4.9.10 ---------------------------------------
			¥ removed sub navigation and information
			¥ 1st slide shows up on page load
			¥ subsequent slides are then random
			¥ sped up rotation from 7500 to 5000
	*/		
	
	
	$(document).ready(function(){
		
		// turn gallery components on
		$('#home_bucket_1').addClass('gallery_on');
		$('#gallery_info').show();
		var num_slides = 0;
		
		// add navigation
		$('#home_page_gallery_images li').each(function(i){
			
			// hide images
			$(this).hide();
			
			// index slides
			num_slides++;
			
			// add id's to current li for nav later
			$(this).attr('id', 'hg_img_'+ (i+1));
			
			// add li elements to nav
			var alt = $(this).find('img').attr('title');	
			$('#gallery_pages ul').append('<li><a href="#hg_img_' + (i+1) + '" alt="' + alt + '">' + (i+1) + '</a></li>');
			$('#gallery_pages ul li:eq(0) a').addClass('current');
			
			$(this).parent().find('br').remove();
		
		});
		
		
		// hide navigation
		var gallery = $('#gallery_info').hide();
		var gallery_started = false;
		
		// activate navigation
		$('#gallery_pages a').click(function(event){
			
			// find current
			var current = $('#home_page_gallery_images li.current').attr('id');
			$('#home_page_gallery_images li.current').fadeOut('slow').removeClass('current');
			
			// show new
			if (gallery_started) {
				var show = 'hg_img_' + (Math.floor(Math.random() * num_slides) + 1);
				// prevent 2 in a row
				if (current == show) {
					show = 'hg_img_' + (Math.floor(Math.random() * num_slides) + 1);
				}
			} else {
				var show = 'hg_img_1';
				gallery_started = true;
			}
			$('#home_page_gallery_images #' + show).fadeIn('slow').addClass('current');
			
			event.preventDefault();
		
		});
		
		
		// trigger first image
		$('#gallery_pages a:eq(0)').trigger('click');
		
		
		// timer
		var hp_links = new Array();
		$('#gallery_pages a').each(function(i) {
			hp_links[i] = $(this);
		});
		
		var next 	= 1;
		var pause = 9000;
		function loop() {
			
			timer = setTimeout ( function() {
				
				// trigger links
				$(hp_links[next]).trigger('click');
				
				if (next > hp_links.length-2) {
					next = 0;
					} 
				else {
					next++;
					}
				
				pause = 6500;
				
				// call loop again
				loop();
				}, pause
				
			);
			
		}
		
		loop();

		$('#btm').click(function(){
			$('#home_bucket_1 iframe').remove();
			$('#home_bucket_1').css('height','494px')
			$('#home_page_gallery_images').show();
			$('#back_to_marquee').hide();
			return false;
			// 
		});

		// fix links
		$('#home_page_gallery_images a[href*="/giftcardnewsletter_marquee"]').click(function(){
			$('#news_up').trigger('click');
			return false;
		});

		
		$('#home_page_gallery_images a[href*="switch_hpv_annefontaine"]').attr('href', '/store-listings/anne-fontaine/');						
		
		$('#home_page_gallery_images a[href*="switch_hpv_ysl"]').attr('href', '/store-listings/ysl');

		$('#home_page_gallery_images a[href*="switch_hpv_hwinston"]').attr('href', '//store-listings/harry-winston/');

		$('#home_page_gallery_images a[href*="switch_hpv_billyreid"]').attr('href', '/store-listings/billy-reid-2');

		$('#home_page_gallery_images a[href*="switch_hpv_jimmychoo"]').attr('href', '/store-listings/jimmy-choo/');



/*

				
		
				
		$('#home_page_gallery_images a[href*="tory"]').click(function(){
			$('#home_bucket_1').append('<iframe src="http://player.vimeo.com/video/14842121?byline=0&amp;portrait=0&amp;color=c2b26d&amp;autoplay=1" width="1001" height="563" frameborder="0"></iframe>').css('height','563px');
			$('#home_page_gallery_images').hide();
			$('#back_to_marquee').show();
			
			return false;
		});
		
*/




		if ($('#small_grid_gallery .video').attr('title') == 'Make Yourself At Home Video') {
			$('#small_grid_gallery .video img').attr('src', 'http://www.hpvillage.com/wp-content/themes/hp_village/_img/Video_Marquee.jpg');
		}
	
		
		
		
		
	});
	
	
	
	
	
