jQuery(document).ready(function($){

	Cufon.replace('#rotating-callouts .cufon, .cufon, #shopping-cart-table thead span, .step-title .number, .data-table thead span, .block-title h1, .page-title h1, .step-title', {hover: true});

	//Open Link in New Window
	$('a[rel^=external]').click( function() {
		window.open(this.href);
		return false;
	});

	//Form Elements 
		$('input[type="text"]').focus(function() {
			//$(this).removeClass("idleField").addClass("focusField");
	 		if (this.value == this.defaultValue){ 
	 			this.value = '';
			}
			if(this.value != this.defaultValue){
	   			this.select();
	   		}
		});
		$('input[type="text"]').blur(function() {
	 		//$(this).removeClass("focusField").addClass("idleField");
	 		if ($.trim(this.value) == ''){
	  			this.value = (this.defaultValue ? this.defaultValue : '');
			}
	 	});

	//Homepage Carousel
		$('#home_carousel').slideshow({
			slideshowTimer : 6000,
			autoSlide : true
		});

	//Homepage Rotating Callouts
		if ($.browser.msie && $.browser.version.substr(0,1)<9) {
	        $('#rotating-callouts').jcarousel({
	        	initCallback: mycarousel_initCallback,
	        	buttonNextHTML: null,
	        	buttonPrevHTML: null
	        });
		} else {
	        $('#rotating-callouts').jcarousel({
	        	wrap: "circular",
	        	initCallback: mycarousel_initCallback,
	        	buttonNextHTML: null,
	        	buttonPrevHTML: null
	        });
		}

	// Homepage Lightbox
		$('.cms-home .colorbox').live('click', function() {
		  url = this.href;
		  $.fn.colorbox({href: function() {return url}, iframe:'true', innerHeight:'390px', innerWidth:'638px'});
		  return false;
		});
	
	//Exclusive Collection Dropdown
		$('#ex_link').click(function(){
			if ($('#exclusive_sel').attr('value') == '') {
				return false
			} else {
				window.open(this.href);
				return false;
			}
		})
		$('#exclusive_sel').change(function(){
			exclusive_link = $(this).attr('value');
			$('#ex_link').attr("href", exclusive_link);
		});
	
	//Store Locator Hide honora on click
		$('.store-three #store-sub').click(function(){
			$('.h_store').slideUp();
			$('.local_jew').removeClass('local_jew');
			$('.exclusive_col').hide();
		});
		
	//Product Listings dropdown link
		$('.filter_nav').change(function(){
			var url = $(this).find('option:selected').attr('value');
			if(url) { window.location = url; }
		});

	//Product Zoom
		var zoomValue = "false";
		$('.zoom_btn').click(function(){
			if (zoomValue == "false") {
				zoomValue = true;
				openZoom();
			} else {
				closeZoom();
				zoomValue = false;
			}
			return false;
		});

		$('#image').click(openZoom);
		$('.close_btn, #big-image').click(closeZoom);

		function openZoom() {
			$('.product-shop, #related_products').hide();
			var ImageUrl = $('#image').attr('longdesc');
			var NewImage = new Image();
		   	NewImage.onload = function() {
				$('.product-img-box').animate({'width':NewImage.width,'height' : NewImage.height}, 600);
				$('#big-image').css('top','0px');
				$('#big-image, #zoom').animate({'width':NewImage.width, 'height':NewImage.height}, 600);
				$('#zoom').show();
				$('.zoom_zoom').removeClass('zoom_btn');
				$('.zoom_zoom').addClass('close_btn');
				$('.zoom_zoom').html('Zoom Out');
				$('.left_arr').hide();
		   	}
			NewImage.src = ImageUrl;
			$('#big-image').attr('src', ImageUrl);
			return false;
		}
		function closeZoom() {
			$('.zoom_zoom').html('Zoom In');
			$('.zoom_zoom').removeClass('close_btn');
			$('.zoom_zoom').addClass('zoom_btn');
			$('#big-image, #zoom').animate({'width':'480px', 'height':'506px'}, 600, function() { $('#zoom').hide(); $('.product-shop, #related_products').fadeIn('fast'); }); //Set width and height to the dimension of your image
			$('.product-img-box').animate({'width':'480px','height' : '506px'}, 600);	//Set width and height to the dimension of your image
			$('.left_arr').show();
			return false;
		}

	// Details Page Related Products Tab
		$('.mini-products').hide();
		$('#related_tab ul li:eq(0)').addClass('selected');
		$('#related_box > div:eq(0)').show();
		var current_tab = '';

		$('#related_tab li').click(function(){
			$('#related_tab li').removeClass('selected');
			$('#related_box > div').hide();
			$(this).addClass('selected');
			current_tab = $('#related_tab li').index(this);
			$("#related_box > div:eq("+ current_tab +")").show();
			return false;
		});

	//Product Reviews
		$('#review-form').hide();
		$('.write_review').click(function(){
			$('#review-form').slideToggle("slow");
			$(this).hide();
			return false;
		});

	// FAQ
		$('#questions > li').children('a').click(function() {
			$('#questions li ul').slideUp();
			$('#questions > li').children('a').removeClass('selected');
			$(this).addClass('selected');
			var href = $(this).attr('href');
			$(href).slideDown('slow');
			return false;
		});
		$('#questions li li a').click(function() {
			$('#questions li li a').removeClass('selected');
			$('.cms-page-view #answers > li').slideUp();
			var href = $(this).attr('href');
			$(href).slideDown();
			$(this).addClass('selected');
			return false;
		});

	// Sitewide WP Dropdown Menus
		$(".dropdown dt > a").click(function() {
            $(".dropdown dd ul").toggle();
			return false;
        });
        $(document).bind('click', function(e) {
            var $clicked = $(e.target);
            if (! $clicked.parents().hasClass("dropdown"))
                $(".dropdown dd ul").hide();
        });

	//Blog sidebar
		$('.featured-posts li').hover(function(){
		    $(this).addClass("hover");
		  },function(){
		    $(this).removeClass("hover");
		  }
		);
		$('.wide-thumbs-carousel li').hover(function(){
		    $(this).addClass("hover");
		  },function(){
		    $(this).removeClass("hover");
		  }
		);
		
	//Blog sidebar make entire div clickable
		$(".clickable").click(function() {  
			window.location = $(this).find("a").attr("href");  
		});

	//Conversations Page form
		$('.trigger').click(function() {
			$('#comment-text').toggle('slow');
			$('.trigger').hide();
		});

	//TV
		//Mouseover on thumb
		$('.cat-tv .post').mouseover(function(){
			var children = $(this).children('.overlay');
			children.stop(true,true).fadeIn('fast');
		});
		$('.cat-tv .post').mouseleave(function(){
			var children = $(this).children('.overlay');
			children.stop(true,true).fadeOut('fast');
		});
		
		//Lightbox
		$('.cat-tv .colorbox').colorbox({
			iframe:'true',
			innerHeight:'390px',
			innerWidth:'638px', 
			href: function() {var url = $(this).attr('title'); return url}
		});
		
		//Click disabled on dropdown menu
		$('.thin-head .dropdown dt > a').click(function(){
			return false;
		});

	//Ad
		$('#advertisements-slider').jcarousel({
			rtl: false,
			animation: "slow",
			wrap: "circular"
		});

		$('#advertisements-slider li').hover(
		  function () {
		    $(this).find('.btn-grey').fadeIn('fast');
		  }, 
		  function () {
		    $(this).find('.btn-grey').fadeOut('fast');
		  }
		);

	//Ad details
		$('#ad_products ul').jcarousel({
			wrap: "circular",
			scroll: 2
		});
		$('.single-post .colorbox').colorbox({inline: true, href:"#ad"});

	//Carousel for Shapes, Colors and Exclusive Collections Pages 
		$('.wide-thumbs-carousel').jcarousel({
			animation: "slow",
			//wrap: "circular",
			scroll: 5
		});

		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		} else {
			$('.tools').tooltip();
		}

		$('.wide-thumbs-carousel .jcarousel-item').hover(function(){
			var bodyX = $('#wrapper').offset().left; //Get X Position of Wrapper in relation to the document (BODY)
			var x = $(this).offset().left; //Get X Position of carousel item in relation to the document (BODY)
			var posX = x - bodyX;

			if (posX > 700) {
				$(this).children('div').removeClass('tooltip');
				$(this).children('div').addClass('tooltip_r');
			}
		});

	//Newsletter Lightbox and form
		$('#footer .newsletter-btn').colorbox({onOpen:function(){$('#mc-embedded-subscribe-form-footer').submit();}, inline: true, width: "25%", height: "130px", href:"#mce-responses-footer"});
		$(document).live('cbox_closed', function(){
			$('#mce-responses-footer .mce-success-responses').empty();
			$('#mce-responses-footer .mce-error-responses').empty();
		});
		$('.con_tainer .newsletter-btn').colorbox({onOpen:function(){$('#mc-embedded-subscribe-form-sidebar').submit();}, inline: true, width: "25%", height: "130px", href:"#mce-responses-footer"});
		$(document).live('cbox_closed', function(){
			$('#mce-responses-footer .mce-success-responses').empty();
			$('#mce-responses-footer .mce-error-responses').empty();
		});
		
	//Twitter widget
		$("#twitter-container").tweet({
			username: "honorapearls",
			join_text: "auto",
			avatar_size: 32,
			count: 20,
			auto_join_text_default: "",
			auto_join_text_ed: "we",
			auto_join_text_ing: "we were",
			auto_join_text_reply: "we replied to",
			auto_join_text_url: "",
			loading_text: "loading tweets..."
		});

});

function mycarousel_initCallback(carousel) {
    jQuery('#main-container .sliderNav .next').bind('click', function() {
        carousel.next();
        Cufon.refresh('#rotating-callouts .cufon, .cufon, #shopping-cart-table thead span, .step-title .number, .data-table thead span, .block-title h1, .page-title h1, .step-title', {hover: true});
		return false;
    });
    jQuery('#main-container .sliderNav .previous').bind('click', function() {
        carousel.prev();
        Cufon.refresh('#rotating-callouts .cufon, .cufon, #shopping-cart-table thead span, .step-title .number, .data-table thead span, .block-title h1, .page-title h1, .step-title', {hover: true});
		return false;
    });
};
