//===============================================
// PAGE INIT

jQuery(function($){

	//===============================================
	// LOGIN FORM
	
	var login_button	=	$('.login-button');
	var dialog_html		=	'<div class="dialog"></div>';
	var dialog_height	=	500;
	var dialog_width	=	1040;
	var ajax_url		=	'/account/login .memberPage';

/*
	login_button.click(function(event){

		event.preventDefault();

		var dialog = $( dialog_html );

		dialog.appendTo('body');
		
		dialog.load(
			ajax_url,
			{},
			function (responseText, textStatus, XMLHttpRequest) {
				dialog.dialog({
					draggable	: false,
					height		: dialog_height,
					modal		: true,
					width		: dialog_width
				});
			}
		);
	});
*/

	//===============================================
	// HEADER SEARCH INPUT STATES

	$('.header-search').focus(function() {
		$(this).val('');
	}).blur( function() {
		if(	$(this).val() != 'Search' )	$(this).val('Search');
	});

	//===============================================
	// HEADER CART ANIMATION
	
	var headerCartDuration	=	500;
	var headerCartEasing	=	'easeInOutExpo';
	var headerCartContent	=	$('.header-cart-content');
	headerCartContent.hide();
	$('.header-cart .cart-toggle').click(function(event){
		event.preventDefault();
		headerCartContent.slideToggle({
			'duration'	: headerCartDuration,
			'easing'	: headerCartEasing
		});
	});

	//===============================================
	// ASIDE COLLAPSIBLES

	var asideDuration	=	500;
	var asideEasing		=	'easeInOutExpo';
	var asideContent	=	'.aside-collapsible-content';
	$( asideContent ).hide();
	$('.aside-collapsible h4 a').click(function(event){
		event.preventDefault();
		$(this).parents('.aside-collapsible')
			.find( asideContent )
			.slideToggle({
				'duration'	: asideDuration,
				'easing' 	: asideEasing
			}
		);

	});

	//===============================================
	// CAROUSELS

	$('.big-gallery-next a, .big-gallery-prev a').hide();
	$('.big-gallery ul.big-gallery-images').cycle({
	    fx		: 'scrollHorz',
	    easing	: 'easeInOutExpo',
	    speed	: 'fast',
	    nowrap	: 1,
	    timeout	: 0,
	    next	: '.big-gallery-next',
	    prev	: '.big-gallery-prev',
	    after	: onAfterSlideClick

	});

	//===============================================
	// ASIDE GALLERIES

	$('.aside .aside-gallery .aside-gallery-thumbs li a').mouseover( function (event) {
		var gallery			= $(this).parents('.aside-gallery');
		var galleryThumb	= $('img', this);
		var galleryImgLink	= $('.aside-gallery-preview a', gallery);
		var galleryImg		= $('img', galleryImgLink);
		console.log(gallery, galleryImg, galleryImgLink);
		galleryImgLink.attr({
			'href'	: $(this).attr('href'),
			'title'	: $(this).attr('title')
		});
		galleryImg.attr({
			'src'	: galleryThumb.attr('src'),
			'alt'	: galleryThumb.attr('alt')
		});
	});

});

//===============================================
// CAROUSEL FUNCTIONS

// Manage navigation states after slide is clicked
function onAfterSlideClick(curr, next, opts) {
    var index = opts.currSlide;
    jQuery('.big-gallery-prev a')[index == 0 ? 'hide' : 'show']();
    jQuery('.big-gallery-next a')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}

// BOX CLICKS


$(document).ready(function(){
    var block = $(".grid-meta,.article-splash,.button-releases-nav");
    block.click(function(){
        window.location = $(this).find("a:first").attr("href")
    });
    block.addClass("clickable");
    block.hover(function(){
        window.status = $(this).find("a:first").attr("href")
    }, function(){
        window.status = ""
    })
});

