jQuery.noConflict(); 

jQuery(document).ready(function() {

		jQuery("#main-nav a:last").css("margin-right","0px");

		jQuery("#frame-content").cycle({
			pager:  '#frame-tabs', 
    		pagerAnchorBuilder: function(idx, slide) { 
        		// return selector string for existing anchor 
        		return '#frame-tabs a:eq(' + idx + ')'; 
			}, 
		  	before: function(curr,next,opt,flag){
				index = "#ft" + jQuery("#frame-content img").index(next);
				jQuery(index).addClass('active');
				jQuery("#ft3").addClass('active');
				jQuery("#ft2").addClass('active'); 
				jQuery("#ft1").addClass('active');
			}
		});

		jQuery("#about-right-slideshow, .slideshow").cycle();

		jQuery("#content.shop-home + #footer").css("margin-top","-5px");

		jQuery('.utility-modal').prepend('<a href="#" class="close_btn">Close</a>');
		jQuery('.utility-modal .close_btn').click(function(){
			jQuery('.utility-modal').fadeOut();
			return false;
		});

//CREATE THE COLOR SWATCHES
      var foo = [];
      var color_label = '';
      var color_code = '';
      var inside_default_option = '';
      var outside_default_option = '';
      if(jQuery('.product-custom-option option').length > 0){
      	jQuery('#product-options-wrapper dt label').each(function(i, selected){
      		//Start magic
      		color_label = jQuery(selected).html();
      		color_code = color_label.replace(' ','-');
      		color_code = color_code.toLowerCase();
			//alert(color_code);
      		if(color_code == 'color')
      			color_code = 'inside-color';
      		jQuery("#selected-color").append("<span id='color-title'>"+color_label+": </span>");
      		
      		jQuery('dd.last select.product-custom-option').removeClass('required-entry').parent().parent().hide();
      		jQuery('#product-options-wrapper p.required').hide();
      
      jQuery(selected).parent().next().find('select option').each(function(i, option){
			if (jQuery(option).val()) {
				foo[i] = jQuery(option).text().split(" #");
				//console.info(foo[i]);
				if(foo[i][0] == 'let artist choose'){
					if(color_code == 'inside-color')
						inside_default_option = jQuery(option).val();						
					if(color_code == 'outside-color')
						outside_default_option = jQuery(option).val();
					if(color_code == 'interior-color')
						inside_default_option = jQuery(option).val();
						
					if(color_code == 'exterior-color')
						outside_default_option = jQuery(option).val();	
				}
				
				jQuery("#selected-color").append("<div id='c" + jQuery(option).val() + "' class='"+color_code+"'><span class='current-swatch' style='background-color: #" + foo[i][1] + "' ><a rel='"+foo[i][0]+"-"+jQuery(option).val()+"' href='#' class='color-link' title='"+foo[i][0]+"'><img src='http://www.rwoodstudio.com/skin/frontend/default/blank/images/bg-swatch-large.png' alt='"+foo[i][0]+"' /></a></span></div>");

				jQuery("#second-color").append("<div id='c2" + jQuery(option).val() + "'><span class='current-swatch' style='background-color: #" + foo[i][1] + "' ><a rel='"+foo[i][0]+"-"+jQuery(option).val()+"' href='#' class='color-link' title='"+foo[i][0]+"'><img src='http://www.rwoodstudio.com/skin/frontend/default/blank/images/bg-swatch-large.png' alt='"+foo[i][0]+"' alt='' /></a></span></div>");

				jQuery("#color-list").append("<li value='" + jQuery(option).val() + "' title='" + foo[i][0] + "''><a  rel='"+foo[i][0]+"-"+jQuery(option).val()+"' href='#' class='color-link' title='"+foo[i][0]+"'><img src='http://clients.jhuskisson.com/r/rwood/ee/images/site/bg-swatch-small.png' style='background-color: #" + foo[i][1] + "' alt='" + foo[i][0] + "' /></a></li>");
			//console.info(foo[i][1]);
			}
      });
      		//End
      	});
      	}
      
      
	  if(jQuery('.product-custom-option option').length > 0){
      	
      	jQuery('#product-options-wrapper dt label').each(function(i, selected){
      		color_label = jQuery(selected).html();
      		color_code = color_label.replace(' ','-');
      		color_code = color_code.toLowerCase();
      		console.info(jQuery(selected).parent().next().find('select').attr('name'));
      		if(color_code == 'color')
      			color_code = 'inside-color';
      		if(color_code == 'inside-color')
      			jQuery("#selected-color").append("<input id='inside-color-value' type='hidden' value='"+inside_default_option+"' name='"+jQuery(selected).parent().next().find('select').attr('name')+"'/>");
      		if(color_code == 'outside-color')
      			jQuery("#selected-color").append("<input id='outside-color-value' type='hidden' value='"+outside_default_option+"' name='"+jQuery(selected).parent().next().find('select').attr('name')+"'/>");
			if(color_code == 'interior-color')
      			jQuery("#selected-color").append("<input id='interior-color-value' type='hidden' value='"+inside_default_option+"' name='"+jQuery(selected).parent().next().find('select').attr('name')+"'/>");
      		if(color_code == 'exterior-color')
      			jQuery("#selected-color").append("<input id='exterior-color-value' type='hidden' value='"+outside_default_option+"' name='"+jQuery(selected).parent().next().find('select').attr('name')+"'/>");	
      		
      		jQuery("#selected-color").append("<span id='"+color_code+"'>Current selected "+color_label+": <strong id='"+color_code+"-selected'>let artist choose</strong></span>");
      	});
      	jQuery('dd select.product-custom-option').remove();
      }
	  	jQuery(".inside-color a.color-link").click(function(e){
			e.preventDefault();
			var rel = jQuery(this).attr('rel');
			rel = rel.split('-');
			console.info(rel[1]);
			jQuery("input#inside-color-value").val(rel[1]);
			jQuery('strong#inside-color-selected').html(rel[0]);
		});
		
		jQuery(".outside-color a.color-link").click(function(e){
			e.preventDefault();
			
			var rel = jQuery(this).attr('rel');
			rel = rel.split('-');
			console.info(rel[1]);
			jQuery("input#outside-color-value").val(rel[1]);
			jQuery('strong#outside-color-selected').html(rel[0]);
		});
		jQuery(".interior-color a.color-link").click(function(e){
			e.preventDefault();
			var rel = jQuery(this).attr('rel');
			rel = rel.split('-');
			console.info(rel[1]);
			jQuery("input#interior-color-value").val(rel[1]);
			jQuery('strong#interior-color-selected').html(rel[0]);
		});
		
		jQuery(".exterior-color a.color-link").click(function(e){
			e.preventDefault();
			
			var rel = jQuery(this).attr('rel');
			rel = rel.split('-');
			console.info(rel[1]);
			jQuery("input#exterior-color-value").val(rel[1]);
			jQuery('strong#exterior-color-selected').html(rel[0]);
		});
		
	
		jQuery("#primary-color .remove-color a").click(function(){
			jQuery("#color-list li, #selected-color div").removeClass("selected1");
			jQuery("#second-color div").removeClass("selected2");
			jQuery("#primary-color").addClass("active");
			jQuery("input.product-custom-option").val("");
			jQuery("select").val("");
			return false;
		});


		jQuery(".frame1:odd").removeClass("frame1").addClass("frame2");

		jQuery('.quick-look').hide();
		jQuery(".product-listing-image, .quick-look").hover(
			function(){jQuery(this).parent().find('.quick-look').show();},
			function(){jQuery('.quick-look').hide();}
		);					
		jQuery('.button-continue').click(function(){
			jQuery('.quick-look').hide();
			return false;
		});
		
		var limit = jQuery('.slide').length;
		var i = 0;
		jQuery('a#view-more').click(function(){
			i++;
			if(i < limit){
				var topX = "-" + i*parseInt(jQuery('.slide').css('height')) + "px";
				jQuery('.slides-wrap').stop().animate({'top':topX}, 1000);
			}else{
				i=0;
			}
			return false;
		});
		
		
		
		//	QUICKLOOK FUNCTIONALITY
		// jQuery(".product-listing").hover(
		// 	function(){jQuery(".product-listing-image .quicklook-icon",this).show();},
		// 	function(){jQuery(".product-listing-image .quicklook-icon",this).hide();}
		// );					
		// 
		// jQuery(".quicklook").hover(
		// 	function(){jQuery(".quick-look",this).addClass("shown");},
		// 	function(){jQuery(".quick-look",this).removeClass("shown");}
		// );					
		// 
		// jQuery("a.button-continue").click(function(){
		// 		jQuery(this).parents(".quick-look").removeClass("shown");
		// 		return false;
		// });

		

});	



