$j(function() {
	
	$j('.blink').focus(function() {
		if(this.value == this.title) {
			this.value = ''
		}
	}).blur(function() {
		if(this.value == '') {
			this.value = this.title
		}
	});
	
	$j('.popup-close, .popup-cancel, .close-button').live('click', function() {
		//$j(this).parents('.popup:eq(0)').hide();
        $j(this).parents('.popup:eq(0)').addClass('no-display');
		return false;
	});


    $j('.category-products select:not(.address-select)').selectbox();
	$j('.customer-account select:not(.address-select)').selectbox();
    $j('.return-guest-form select').selectbox();
	$j('.return-request-index select').selectbox();

	$j('.cart-container .button').mouseover(function() {
		$j(this).parent().find('.cart-dd').show();
	});
	$j('.cart-dd').mouseleave(function() {
		$j(this).hide();
	});
	
	$j('#nav li').hover(function() {
		$j(this).find('.dd').toggle();
	});
	
	$j('span[class*="color"]').hover(function() {
		$j(this).toggleClass('color-hover');
	});
	
//	$j('.tab-links a').click(function() {
//		$j(this).parent().addClass('current').siblings('.current').removeClass('current');
//		return false;
//	});

    $j("#description-tabs .tab-links a").live('click', function(){
        var idx = $j(this).parent().index();
        $j('#description-tabs .tab-links a').parent().removeClass('current');
        $j(this).parent().addClass('current');
        $j('#description-tabs .tab-entries .tab-entry').hide();
        $j('#description-tabs .tab-entries .tab-entry').eq(idx).show();
        return false;
    });
	
	resize();
	
	$j(window).resize(function() {
		resize();
	});
	
	
	$j('.row').hover(function() {
		$j(this).toggleClass('row-hover');
	});

	// fashion weeek gallery	
	if($j('#gallery').length) {
		$j('#gallery .large .container').flexslider({
			animation: 'slide',
			slideshow: false,
			animationDuration: 800,
			controlNav: false,
			keyboardNav: false,
			prevText: 'last',
			nextText: 'next',
			animationLoop: false,
			start: function(slider) {
				slider.directionNav.appendTo('#gallery .large .arrows');

				$j('#gallery .thumbs img').bind('click', function() {
					var idx = $j(this).parent().index();
					slider.flexAnimate(idx);
				});
			}
		});
	}
});

function resize() {
	
	//$j('#background').css('height', $j('#wrap').height());
        
        var h = $j('#wrap').height();
        var w = $j('#wrap').width();
        
        // get browser inner screen width and height. (check browser compatibility)
        if (window.innerHeight) {
            h = window.innerHeight;
            w = window.innerWidth;
        } else if (document.body.clientHeight) {
            h = document.body.clientHeight;
            w = document.body.clientWidth;
        } else if (document.documentElement.clientHeight) {
            h = document.documentElement.clientHeight;
            w = document.documentElement.clienWidth;
        }
                
        var e = document.documentElement;
        $j('#background').css('height', h).css('width', w); // set background height and width to actual screen size
        
	/*
	var win_wid = $j(window).width();
	if(win_wid < 1300 && win_wid > 1180 && $j('#sidebar').length == 0) {
		$j('.shell, #header, #nav').css('width', win_wid-100);
	}
	*/
}

// checks if value is in array or not (returns true if value is in array or false otherwise)
function inArray(value, array)
{
    for (var i=0; i<array.length; i++) {
        if (array[i] == value) {
            return true;
        }
    }
    return false;
}

function validateEmail(v)
{
    return /^([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9,!\#\$%&'\*\+\/=\?\^_`\{\|\}~-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*@([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z0-9-]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*\.(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]){2,})$/i.test(v);
}

function validateDigit(v)
{
    return (/\D+/.test(v) != true);
}

function record_history(json_response) {	
	// store resulting URL order in $.store
	var items = [];
	for (var i = 0, len = json_response.response.docs.length; i < len; i++) {
		var item = json_response.response.docs[i];
		var pi = {
			'id' : item.product_id,
			'url' : item.product_url_stored_text_attribute.toString()
		};
		items.push(pi);
	}
	
	$j.jStorage.set('search_items', items);
}
