/* ---------------------------------------------------- */
// various scripts used around the site
/* ---------------------------------------------------- */
var script = {
    cufon : '/js/cufon.js',
//    cycle : '/js/jquery.cycle.all.min.js',
    cycle : '/js/jquery.cycle.min.js',

    colorbox : '/js/jquery.colorbox.min.js',
    swfobject : '/js/swfobject.js',
    optpopup : '/js/jquery.opt.popup.js'
}


var tj = {
    
    abc : {
        
        init : function() {
					tj.misc_func.init_breadcrumbs();
        }

    },
    
    home : {
        
        init : function() {
            this.slides();
        },
        
        slides : function() {
            $.getScript(script.cycle, function() {
                $('.slide_module').cycle({ fx: 'fade', timeout: 5000, speed: 2000 }); // bottom right slider
                //$('#home_slides').cycle({ fx: 'fade', timeout: 5000, speed: 2000 }); // main home slider     
            });
        }
        
    },
    
    spotlight : {
        
        init : function() {
            this.toggle_more();
            this.lightbox_slides_trigger();
        },
        
        toggle_more : function() {            
            $('#read_more').click(function(e) {
                tj.misc_func.cancel(e);
                
                if($('#spotlight_more').is(':visible')) {
                    $(this).empty().append('More +');
                } else {
                    $(this).empty().append('Less -');
                }
                
                $('#spotlight_more').slideToggle();
            });
        },
        
        lightbox_slides_trigger : function() {
            $('.spotlight_slide_trigger').click(function(e) {
                $('.slide_image:first').click();
                return false;
            });
        }
        
    },
    
    services : {
	
	  	init : function(){
			this.askGoldsmith();
			
		},
        
		askGoldsmith : function() {
			
			$('a.ask_goldsmith').optPopup($('a.ask_goldsmith').attr('href'), function() {
				var goldsmithForm = $('#goldsmithForm');

				goldsmithForm.validate({
					submitHandler: function(form) {
						postUrl = goldsmithForm.attr('action');

						$.ajax({
							type: "POST",
							url: postUrl,
							data: goldsmithForm.serialize(),
							success: function(data) {
								$('.goldsmithMessage').html(data);

								if (typeof (Cufon) != "undefined" && Cufon != null) {
									Cufon.refresh();
								}

								setTimeout(function() { 
									$('#close_button').click(); }, 3000);
								}
							});
							return false;
						}
					});
			});
		}
        
    },
    
    // misc_ functions
    misc_func : {
	 
				cancel : function(e) {
					if (e && e.preventDefault)
						e.preventDefault(); // DOM style
					return false; // IE style
				},
        
        page_slides : function() {
            $.getScript(script.cycle, function() {
                $('#page_slides').cycle({ fx: 'fade', timeout: 5000, speed: 2000 });
            });
        },
        
        lightbox : function() {
            $.getScript(script.colorbox, function() {
                $("a[rel='lightbox']").colorbox({scalePhotos: true});
            });
        },
        
        lightbox_video : function() {   
            $.getScript(script.swfobject);
            $.getScript(script.colorbox, function() {
                $("a[rel='lightbox']").colorbox({width:"564", height:"502", iframe:true});
            });
        },
        
        lightbox_periodicals : function() {
            $.getScript(script.swfobject);
            $.getScript(script.colorbox, function() {
                $("a[rel='lightbox']").colorbox({width:"95%", height:"95%", iframe:true});
            });
        },

        lightbox_locations : function() {
            $.getScript(script.colorbox, function() {
                $("a[rel='lightbox-1']").colorbox({scalePhotos: true});
								$("a[rel='lightbox-2']").colorbox({scalePhotos: true});
            });

						$('.location_slide_button-1').click(function(e) {
							tj.misc_func.cancel(e);
							$('.slide-1:first').trigger('click');
						});
			
						$('.location_slide_button-2').click(function(e) {
							tj.misc_func.cancel(e);
							$('.slide-2:first').trigger('click');
						});
			
        },
        
        landing_slides : function() {
            $.getScript(script.cycle, function() {
                $('.landing_slides').cycle({
                    fx: 'fade',
                    timeout: 5000,
                    speed: 2000,
                    pager: '.landing_slides_pager',
                    pagerAnchorBuilder: function(idx, slide) {
											return '<li><span class="pager_item">.</span></li>'; 
                    } 
                });
            });
        },
				bridal_cycle:function(){
					$.getScript(script.cycle, function() {
              $('.right').cycle({ fx: 'fade', timeout: 5000, speed: 2000 });

          });
				},
				
				learn_more:function(){
					$('a.learn_more +span').hide();
					$('a.learn_more').click(function(){
						$('a.learn_more +span').toggle();
						return false;
					});
        },

        init_breadcrumbs : function() {
            $('#breadcrumbs li').each(function(i) {
                var self = this;
                
                if ($(self).is(':last-child')) {
                    $(self).addClass('current');
                } else {
                    $(self).after('<li class="separator">&raquo;</li>');
                }
            });
				},
				
				get_states_list : function() {
					var $state_select = $('select#state');

					// Get the JSON list of states
					$.getJSON('/js/states.js', function(data) {
						$.each(data, function(i, state) {
							// Create the state options and append them to the select list
							$('<option value="'+i+'">'+state+'</option>').appendTo($state_select);
						});
					});	
		},
		
		mothers_day : function() {
			var _hash = window.location.hash.toString().replace('#','');
			$('#collection_container').cycle({
				slideExpr: '.brand_block',
				fx: 'scrollHorz',
				next: '#btn_next',
				prev: '#btn_prev',
				timeout: 0
//				startingSlide: (_hash && _hash !== '#') ? _hash : 0,
//				after: function(current) {
//				console.log($(current).index());
//					window.location.hash = $(current).index();
//				}
			});
		}
    }
}

$(function() {
//	$('.nav').nmcDropDown();
  // tj.global.init(); 
});

/**
 * nmcDropDown plugin - v1.0.4
 * Author: Eli Van Zoeren
 * Copyright (c) 2009 New Media Campaigns
 * http://www.newmediacampaigns.com 
 **/
(function(a){a.fn.nmcDropDown=function(b){var c=a.extend({},a.fn.nmcDropDown.defaults,b);return this.each(function(){var menu=a(this);submenus=menu.children("li:has("+c.submenu_selector+")");if(c.fix_IE){menu.css("z-index",51).parents().each(function(d){if(a(this).css("position")=="relative"){a(this).css("z-index",(d+52))}});submenus.children(c.submenu_selector).css("z-index",50)}over=function(){a(this).addClass(c.active_class).children(c.submenu_selector).animate(c.show,c.show_speed);return false};out=function(){a(this).removeClass(c.active_class).children(c.submenu_selector).animate(c.hide,c.hide_speed);return false};if(c.trigger=="click"){submenus.toggle(over,out).children(c.submenu_selector).hide()}else{if(a().hoverIntent){submenus.hoverIntent({interval:c.show_delay,over:over,timeout:c.hide_delay,out:out}).children(c.submenu_selector).hide()}else{submenus.hover(over,out).children(c.submenu_selector).hide()}}})};a.fn.nmcDropDown.defaults={trigger:"hover",active_class:"open",submenu_selector:"ul",show:{opacity:"show"},show_speed:300,show_delay:50,hide:{opacity:"hide"},hide_speed:200,hide_delay:100,fix_IE:true}})(jQuery);

