jQuery(document).ready(function(){

/* ------------------------------------------ Unite Home Scroller ------------------------------------------ */

	jQuery('#unite_header_gallery').cycle ({
		fx: 'fade',
		speed:500,
		pause:1,
		timeout:6000,
		pager: '#unite_header_nav',
		pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#unite_header_nav li:eq(' + (idx) + ') a';
        }

	});
	
/* ------------------------------------------ Unite Add Adventures ------------------------------------------ */	

	jQuery('#twitter_1').click(function(){
		jQuery('#unite_add_twitter_1').fadeIn(150);
		jQuery('#unite_add_twitter_2').fadeOut(150);
		jQuery('#unite_add_twitter_3').fadeOut(150);
	});

	jQuery('#twitter_2').click(function(){
		jQuery('#unite_add_twitter_1').fadeOut(150);
		jQuery('#unite_add_twitter_2').fadeIn(150);
		jQuery('#unite_add_twitter_3').fadeOut(150);
	});

	jQuery('#twitter_3').click(function(){
		jQuery('#unite_add_twitter_1').fadeOut(150);
		jQuery('#unite_add_twitter_2').fadeOut(150);
		jQuery('#unite_add_twitter_3').fadeIn(150);
	});
	
	
	jQuery('#find_twitter_username').click(function(){
		jQuery('#find_twitter_username_popup').show();	
	});
	jQuery('#close_twitter_popup').click(function(){
		jQuery('#find_twitter_username_popup').hide();	
	});
	
	jQuery('#youtube_1').click(function(){
		jQuery('#unite_add_youtube_1').fadeIn(150);
		jQuery('#unite_add_youtube_2').fadeOut(150);
		jQuery('#unite_add_youtube_3').fadeOut(150);
	});

	jQuery('#youtube_2').click(function(){
		jQuery('#unite_add_youtube_1').fadeOut(150);
		jQuery('#unite_add_youtube_2').fadeIn(150);
		jQuery('#unite_add_youtube_3').fadeOut(150);
	});

	jQuery('#youtube_3').click(function(){
		jQuery('#unite_add_youtube_1').fadeOut(150);
		jQuery('#unite_add_youtube_2').fadeOut(150);
		jQuery('#unite_add_youtube_3').fadeIn(150);
	});
	
	
	jQuery('#find_youtube_username').click(function(){
		jQuery('#find_youtube_username_popup').show();	
	});
	jQuery('#close_youtube_popup').click(function(){
		jQuery('#find_youtube_username_popup').hide();	
	});
	
	jQuery('#flickr_1').click(function(){
		jQuery('#unite_add_flickr_1').fadeIn(150);
		jQuery('#unite_add_flickr_2').fadeOut(150);
		jQuery('#unite_add_flickr_3').fadeOut(150);
	});

	jQuery('#flickr_2').click(function(){
		jQuery('#unite_add_flickr_1').fadeOut(150);
		jQuery('#unite_add_flickr_2').fadeIn(150);
		jQuery('#unite_add_flickr_3').fadeOut(150);
	});

	jQuery('#flickr_3').click(function(){
		jQuery('#unite_add_flickr_1').fadeOut(150);
		jQuery('#unite_add_flickr_2').fadeOut(150);
		jQuery('#unite_add_flickr_3').fadeIn(150);
	});
	
	
	
	jQuery('#unite_category').change(function() {
		if (jQuery(this).val() == 'Other') {
			jQuery('#unite_other_category').fadeIn(100);
		} else {
			jQuery('#unite_other_category').fadeOut(100);
		}
	});

	jQuery('#unite_other_category').focus(function() {
		if(jQuery(this).val() == this.defaultValue)
		jQuery(this).val("");
	});

	jQuery('#unite_other_category').blur(function() {
		if(jQuery(this).val() == "")
		jQuery(this).val(this.defaultValue);
	});


/* ------------------------------------------ jScrollPane ------------------------------------------ */	

	jQuery('#unite_feed').jScrollPane({
		dragMaxHeight: 80,
		scrollbarMargin: 0,
		scrollbarWidth: 11
	});
	
	
	jQuery('#browse_categories').jScrollPane({
		dragMaxHeight: 40,
		scrollbarMargin: 0,
		scrollbarWidth: 9
	});

	jQuery('#unite_terms_holder').jScrollPane({
		dragMaxHeight: 40,
		scrollbarMargin: 15,
		scrollbarWidth: 9
	});


/* ------------------------------------------ Leftbar search input ------------------------------------------ */

	jQuery('#search').focus(function() {
		if(jQuery(this).val() == this.defaultValue)
		jQuery(this).val("");
	});

	jQuery('#search').blur(function() {
		if(jQuery(this).val() == "")
		jQuery(this).val(this.defaultValue);
	});
	
/* ------------------------------------------ Leftbar search submit ------------------------------------------ */

	jQuery('#leftbar_search_submit').click(function() {
		
		var searchval = jQuery('#search').val();
		
		if (searchval == "" || searchval == "Search") {
			jQuery('#search').focus();
		
		return false
		
		}
		
		
	
	});

/* ------------------------------------------ Leftbar sort button ------------------------------------------ */

	jQuery('#leftbar_sort').toggle(function() {
		jQuery('#leftbar_sort_dd').slideDown('fast');
		jQuery('#leftbar_sort').addClass('leftbar_dd_open');
	}, function() {
		jQuery('#leftbar_sort_dd').slideUp('fast');
		jQuery('#leftbar_sort').removeClass('leftbar_dd_open');
	});
	
	jQuery('#leftbar_sort').blur(function() {
		jQuery('#leftbar_sort_dd').slideUp('fast');
		jQuery('#leftbar_sort').removeClass('leftbar_dd_open');
	});
		
		
/* ------------------------------------------ Add comment button ------------------------------------------ */

	/*jQuery('#add_comment_button').toggle(function() {
		jQuery('#profile_comments #dsq-new-post').slideDown('fast');
	}, function() {
		jQuery('#profile_comments #dsq-new-post').slideUp('fast');
	});


/* ------------------------------------------ Show Disqus Comments when loaded ------------------------------------------ */

	jQuery(window).load(function() {
		
		setTimeout(function(){
		jQuery("#profile_comments #disqus_thread").slideDown();
		}, 2000);
		
	});
	
/* ------------------------------------------ YouTube gallery scroller ------------------------------------------ */

	jQuery(function() {
		jQuery("div.tubepress_thumbnail_area").smoothDivScroll({ 
			visibleHotSpots: "always",
			scrollWrapper: "div.tubepress_thumbs",
			scrollableArea: "ul.tubepress_thumb_wrapper",
			scrollStep: 60,
			scrollInterval: 15
			});
		});
	
/* ------------------------------------------ Colorbox ------------------------------------------ */

	jQuery('.colorbox').colorbox({opacity:0.8});
	jQuery('.inlinecolorbox').colorbox({inline:true,opacity:0.8});

/* ------------------------------------------ Profile Gallery Tabs ------------------------------------------ */

	jQuery('#profile_gallery_image').click(function() {
		jQuery('#profile_main_image').css('z-index',"300");
		jQuery('#profile_gallery_image').addClass("profile_gallery_active");
		jQuery('#profile_youtube_gallery').css('z-index',"1");
		jQuery('#profile_gallery_youtube').removeClass("profile_gallery_active");
		jQuery('#profile_flickr_gallery').css('z-index',"1");
		jQuery('#profile_gallery_flickr').removeClass("profile_gallery_active");
	});
	
	jQuery('#profile_gallery_youtube').click(function() {
		jQuery('#profile_main_image').css('z-index',"1");
		jQuery('#profile_gallery_image').removeClass("profile_gallery_active");
		jQuery('#profile_youtube_gallery').css('z-index',"300");
		jQuery('#profile_gallery_youtube').addClass("profile_gallery_active");
		jQuery('#profile_flickr_gallery').css('z-index',"1");
		jQuery('#profile_gallery_flickr').removeClass("profile_gallery_active");
	});

	jQuery('#profile_gallery_flickr').click(function() {
		jQuery('#profile_main_image').css('z-index',"1");
		jQuery('#profile_gallery_image').removeClass("profile_gallery_active");
		jQuery('#profile_youtube_gallery').css('z-index',"1");
		jQuery('#profile_gallery_youtube').removeClass("profile_gallery_active");
		jQuery('#profile_flickr_gallery').css('z-index',"300");
		jQuery('#profile_gallery_flickr').addClass("profile_gallery_active");
	});

/* ------------------------------------------ Footer Share links ------------------------------------------ */

	jQuery('#footer_share_delicious').hover(function() {
		jQuery('#footer_share_text').html('<em>Bookmark this page on</em> <span class="color-delicious">Delicious</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_digg').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-digg">Digg</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_facebook').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-facebook">Facebook</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_reddit').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-reddit">Reddit</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_stumbleupon').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-stumbleupon">StumbleUpon</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_technorati').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-technorati">Technorati</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});

	jQuery('#footer_share_twitter').hover(function() {
		jQuery('#footer_share_text').html('<em>Share this page on</em> <span class="color-twitter">Twitter</span>');
		}, function() {
		jQuery('#footer_share_text').html('Use the tools below to share this page');
	});
	
	var fbLink = jQuery('#footer_share_facebook').attr('href');
	fbLink += "&t=";
	fbLink += document.title;
	
	var redditLink = jQuery('#footer_share_reddit').attr('href');
	redditLink += ";title=";
	redditLink += document.title;

	var suLink = jQuery('#footer_share_stumbleupon').attr('href');
	suLink += "&amp;title=";
	suLink += document.title;

	
	jQuery('#footer_share_facebook').attr('href',fbLink);
	jQuery('#footer_share_reddit').attr('href',redditLink);
	jQuery('#footer_share_stumbleupon').attr('href',suLink);


/* ------------------------------------------ Footer Newsletter ------------------------------------------ */

	jQuery('#footer_newsletter_name').focus(function() {
		if(jQuery(this).val() == this.defaultValue)
		jQuery(this).val("");
	});

	jQuery('#footer_newsletter_name').blur(function() {
		if(jQuery(this).val() == "")
		jQuery(this).val(this.defaultValue);
	});


	jQuery('#footer_newsletter_email').focus(function() {
		if(jQuery(this).val() == this.defaultValue)
		jQuery(this).val("");
	});

	jQuery('#footer_newsletter_email').blur(function() {
		if(jQuery(this).val() == "")
		jQuery(this).val(this.defaultValue);
	});
	
	jQuery('#newsletter_footer_submit').click(function() {
		
		var name = jQuery('#footer_newsletter_name').val();
		
		if( name == "Name") {
			jQuery('#footer_newsletter_name').val("")
		}

	});
	
	jQuery("#footer_newsletter").validate({
	rules: {
		footer_newsletter_name: {
			required:true,
			minlength:2
		},
		footer_newsletter_email: {
			required:true,
			email: true
		}
	},
	messages: {
		footer_newsletter_name: "",
		footer_newsletter_email: ""
	},
	success: "valid",
	errorPlacement: function(error, element) {
        error.insertBefore(element);
	}
	
	});
	
	/* ------------------------------------------ Main Newsletter ------------------------------------------ */

	jQuery('#newsletter_model_wrapper').hide();
	jQuery('#newsletter_model_label').hide();

	jQuery('#newsletter_owner').change(function() {
		if (jQuery(this).is(':checked')) {
			jQuery('#newsletter_model_wrapper').fadeIn(100);
			jQuery('#newsletter_owner_check').text('Which model do you own?');
		} else {
			jQuery('#newsletter_model_wrapper').fadeOut(100);
			jQuery('#newsletter_owner_check').text('Are you currently a Nite owner?');
		}
	});

	/* ------------------------------------------ Brochure Request ------------------------------------------ */

	jQuery('#brochure_model_wrapper').hide();
	jQuery('#brochure_model_label').hide();

	jQuery('#brochure_owner').change(function() {
		if (jQuery(this).is(':checked')) {
			jQuery('#brochure_model_wrapper').fadeIn(100);
			jQuery('#brochure_model_label').fadeIn(100);
		} else {
			jQuery('#brochure_model_wrapper').fadeOut(100);
			jQuery('#brochure_model_label').fadeOut(100);
		}
	});

	/* ------------------------------------------ FAQ ------------------------------------------ */

	
	jQuery('#faq_crop_wrapper').css('height','350px').hide(); 
	jQuery('#faq_wrapper').css('height','250px');
	
	jQuery('#faq_questions a').click(function(){
		
		if ( jQuery('#faq_crop_wrapper').css('display') == "none" ) {
			jQuery('#faq_crop_wrapper').slideDown('fast');
		}
	});

	jQuery('#faq_questions').localScroll({
		target:'#faq_wrapper',
		easing:'easeInOutQuart'
	});
	
	
	/* ------------------------------------------ CORPORATE ------------------------------------------ */
		

	jQuery('.corp_international').click(function() {
		jQuery("#radio1").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650);
	});

	jQuery('#corp_international_button').click(function() {
		jQuery('#corporate_international').animate({'top':'30px'},650);
	});
	
	jQuery('.corp_international_apply').click(function() {
		jQuery("#radio1").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650, function() {   
			jQuery('#corporate_international').css('top','1000px');															 
		});
	});



	jQuery('.corp_affiliate').click(function() {
		jQuery("#radio2").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
	jQuery('#corporate_form').animate({'left':'0px'},650);
	});
	
	jQuery('#corp_affiliate_button').click(function() {
		jQuery('#corporate_affiliate').animate({'top':'30px'},650);
	});
	
	jQuery('.corp_affiliate_apply').click(function() {
		jQuery("#radio2").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650, function() {   
			jQuery('#corporate_affiliate').css('top','1000px');															 
		});
	});


	jQuery('.corp_media').click(function() {
		jQuery("#radio3").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650);
	});

	jQuery('#corp_media_button').click(function() {
		jQuery('#corporate_media').animate({'top':'30px'},650);
	});

	jQuery('.corp_media_apply').click(function() {
		jQuery("#radio3").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650, function() {   
			jQuery('#corporate_media').css('top','1000px');															 
		});
	});




	jQuery('.corp_retail').click(function() {
		jQuery("#radio4").attr("checked", true);	
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650);
	});
	
	jQuery('#corp_retail_button').click(function() {
		jQuery('#corporate_retail').animate({'top':'30px'},650);
	});
	
	jQuery('.corp_retail_apply').click(function() {
		jQuery("#radio4").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650, function() {   
			jQuery('#corporate_retail').css('top','1000px');															 
		});
	});


	
	jQuery('.corp_brand').click(function() {
		jQuery("#radio5").attr("checked", true);	
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650);
	});
	
	jQuery('#corp_brand_button').click(function() {
		jQuery('#corporate_brand').animate({'top':'30px'},650);
	});
	
	jQuery('.corp_brand_apply').click(function() {
		jQuery("#radio5").attr("checked", true);
		jQuery.uniform.update();
		jQuery('#corporate_name').focus();
		jQuery('#corporate_form').animate({'left':'0px'},650, function() {   
			jQuery('#corporate_brand').css('top','1000px');															 
		});
	});


	

	jQuery('#corporate_form_close').click(function() {
		jQuery('#corporate_form').animate({'left':'-730px'},500);
	});

	jQuery('#corporate_international_close').click(function() {
		jQuery('#corporate_international').animate({'top':'1000px'},500);
	});

	jQuery('#corporate_affiliate_close').click(function() {
		jQuery('#corporate_affiliate').animate({'top':'1000px'},500);
	});

	jQuery('#corporate_media_close').click(function() {
		jQuery('#corporate_media').animate({'top':'1000px'},500);
	});

	jQuery('#corporate_retail_close').click(function() {
		jQuery('#corporate_retail').animate({'top':'1000px'},500);
	});

	jQuery('#corporate_brand_close').click(function() {
		jQuery('#corporate_brand').animate({'top':'1000px'},500);
	});


/* ------------------------------------------ SHOP - Night image fade ------------------------------------------ */
	
	jQuery('#image_hover').hover(function() {
	jQuery('#main_image').stop(true,true).fadeOut(800);
	}, function() {
	jQuery('#main_image').fadeIn(400);
	});
	
	
/* ------------------------------------------ SHOP - Additional Images ------------------------------------------ */

	jQuery('.add_image').hover(function() {
		
		var add_src = jQuery(this).attr('id');
		
		jQuery('#add_image_wrapper').css('background','url("' + add_src + '") no-repeat');						   
		jQuery('#add_image_wrapper').stop(true,true).fadeIn(550);
	}, function() {
		jQuery('#add_image_wrapper').fadeOut(250);
	});
	
/* ------------------------------------------ SHOP - Home cat rollover ------------------------------------------ */

	jQuery('.store_home_cat').hover(function() {
	jQuery(this).find('em').stop().animate({'left':'6px'},500);
	}, function() {
	jQuery(this).find('em').stop().animate({'left':'200px'},250);
	});



/* ------------------------------------------ SHOP - Owner Story ------------------------------------------ */

	jQuery('.owner_story_colorbox').colorbox({
		iframe:true,
		innerWidth:438,
		innerHeight:622,
		onLoad:	function() {
 		   jQuery('#cboxClose').hide();
		}
	});
	
/* ------------------------------------------ SHOP - Preorder form ------------------------------------------ */

	jQuery("#preorder_form").validate({
		rules: {
			preorder_name: "required",
			preorder_email: {
				required: true,
				email: true
			},
			preorder_tel: "required"
		}
	});


	jQuery('#preorder_form').ajaxForm(function() { 
    	jQuery('#preorder_text').animate({'left':'600px'},500);
    	jQuery('#preorder_success').animate({'left':'0px'},500);
    }); 
	
/* ------------------------------------------------------------------------------------------------- */



});
