(function($){

	$('#searchInput').keyup(function(){
		
		var searchBoxVal = ''+$('#searchInput').val();
		
		if(searchBoxVal.length < 3)
		{
			return;
		}
		
		window.location="http://search.epek.com/#currency=USD&currentCategory=&currentCondition=&currentListingType=All&currentMaxDistance=200&currentPage=1&currentPostcode=&currentSortOrder=BestMatch&currentSuggestion="+searchBoxVal+"&keepAspects=false&maxPrice=10000&minPrice=0&paging=&rnum=353&searchBox="+searchBoxVal+"&showOnlyFeatured=false&showOnlyFree=false";
		
	});
	
    $('input.checkbox').change(function() {
        $(this).siblings('span.checkbox').toggleClass('checked');
    });
    $('input.star').change(function() {
        $(this).siblings('span.star').toggleClass('checked');
    });

	$('#searchMessage input.text').click(function() {
		$(this).val('');
	});
	$('article.product input.text').click(function() {
		$(this).val('');
	});
	
	/* setup .inputdefault fields to have their helper text go away... */
    $('.inputdefault').focus(function(srcc) {
        if ($(this).val() == $(this)[0].title) {
            $(this).val('');
            if($(this).hasClass('password')) {
                try { 
                    // in case an old browser like ie8 or ie7 doesn't like this command
                    $(this).prop('type', 'password');
                } catch(err) {
                    $(this).replaceWith('<input type="password" value="" class="inputdefault password" id="password" style="font-family: Verdana, sans-serif;">');
                    setTimeout(function() {
                       $('#password').focus();
                    });
                }
            }
        }

    });
    /* ...and come back */
    $('.inputdefault').blur(function() {
        if ($(this).val() == '') {
            $(this).val($(this)[0].title);
            if($(this).hasClass('password')) {
                $(this).prop('type', 'text');
            }
        }
    });
	
	/* code needed for account pages only */
	
	$('a.close').click(function(evt) {
		//console.log($(this).parentsUntil('.head'))
		$(this).parentsUntil('.shipping').siblings().toggle();
		evt.preventDefault();
	});
	$('a.closeAddress').click(function(evt) {
		$(this).parentsUntil('.shipping').remove();
		evt.preventDefault();
	});
	
	$('div.form input[readonly="readonly"]').focus(function() {
		$(this).blur();
	});
	
	$('div.star.empty div.rating').hover(function() {
		$(this).prevUntil('div.feedback').toggleClass('active');
	});
	
	/* end: code needed for account pages only */

    /* code needed for seller profile pages only */
    $('#main .seller_review a').click(function(e) {
        e.preventDefault();
        $('.seller_review div').removeClass('selected');
		$(this).parent().addClass('selected');
	});
	/* end: code needed for seller profile pages only */

})( jQuery );
