// TABS
$(function () {
	var tabContainers = $('div.picks > div.tab-content');

	$('div.picks #arrivals .fLeft ul li a').click(function () {
		tabContainers.hide().filter(this.hash).show();
		
		$('div.picks #arrivals .fLeft ul li a').removeClass('selected');
		$(this).addClass('selected');
		
		$('div.picks span.goTo a').attr('href',$(this).attr('rel'));
		$('div.picks span.goTo a span').text($(this).text().toLowerCase());
		return false;
	}).filter(':first').click();
});

// Product images

//function ajax load image with preloader
function load_image(myimg,myimgbig,where,poplnk) {
    //where.html('<img src="/static/images/ajax-loader.gif" class="preload" width="16" height="16" />');
    poplnk.attr('href',myimgbig);
    var img = new Image();
    var link = document.createElement('a');
    where.html('');
    where.append(link);
    $(link).append(img);
    $(link).addClass('MagicZoom MagicThumb');
    $(link).attr('rel', "loading-opacity:50; loading-position-x:150; loading-position-y:20; show-loading:false; zoom-height: 400px; zoom-width: 480px; zoom-distance: 25px;");
    $(link).attr('href', myimgbig);
    $(img).attr('src', myimg);
    MagicZoom.refresh();
    Shadowbox.setup();
}

function prepare_thumbs() {
    //block_b clicking on gallery thumbs
    $(".products-thumbnails .thumbs a").mouseenter(function(){
        var src = $(this).attr("href");
        var big = $(this).attr('rel');
        var where = $(this).parent().parent().parent().find("div.product-image");
        var poplnk = $(this).parent().parent().parent().find("div.product-image a.popup");
        load_image(src,big,where,poplnk);
        return false;
    });
    //block_b clicking on gallery thumbs
    $(".products-thumbnails .thumbs a").click(function(){
        return false;
    });
}

$(document).ready(function() {
    prepare_thumbs();
});


// EMPTY BOXES
$(function () {
  $("input.search-bar").focus(function() { $(this).val(""); });
  $("#form-1").focus(function() { $(this).val(""); });
  });

// Signature
function dot() {
  var _0x8910=["\x23\x64\x6F\x74","\x76\x69\x73\x69\x62\x69\x6C\x69\x74\x79","\x63\x73\x73","\x76\x69\x73\x69\x62\x6C\x65","\x68\x69\x64\x64\x65\x6E","\x64\x6F\x74\x28\x29\x3B"];var p=$(_0x8910[0]);p[_0x8910[2]](_0x8910[1],(p[_0x8910[2]](_0x8910[1])==_0x8910[3])?_0x8910[4]:_0x8910[3]);setTimeout(_0x8910[5],750);
}
$(function () {
  dot();
  });

// Main menu
$(document).ready(function() {
		$("div.menu a.top-level").each(function() {
			$(this).mouseover(function() {
				$("div.list-container li.gender").each(function() {
					$(this).removeClass('selected');
				});
				
				$("ul.first li.gender", $(this).parent()).addClass('selected');
			});
		});
		
		$("div.list-container li").each(function() {
			$(this).mouseover(function() {
				$("div.list-container li.gender").each(function() {
					$(this).removeClass('selected');
				});
				$('li.gender', $(this).parent()).addClass('selected');
			});
		});
});


function states_for_country(country_pk, element, callback) {
  var url = "/accounts/ajax_state/?country=" + country_pk;
  element.load(url, callback);
}

// Kind of specific, but needed on multiple pages
function update_states() {
  states_for_country($("#id_country").val(), $("#id_state"));
}
function update_ship_states() {
  states_for_country($("#id_ship_country").val(), $("#id_ship_state"));
}
function carousel_previous() {
    $(".banners").cycle('prev');
}
function carousel_next() {
    $(".banners").cycle('next');
}

// FAQs ACCORDIONS
$(document).ready(function(){
	$(".toggle_container").hide();
	$("h2.trigger").click(function(){
		$(this).toggleClass("active").next().slideToggle("slow");
	});

});

$(function()
{
 		$('.link-question-container').hide(); 
 		$("a.link-question").click(function () {
        $(this).next().fadeIn();
		$(this).addClass('selected');
     });
	 
	$('a.close').click(function () {
        $(this).parent().fadeOut();
		$(this).parent().parent().children('a.link-question').removeClass('selected')

     });
});

