jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function

// UTILITY NAV
	// move icon backgrounds
	var bgpos = 0;
	$('#sub_links li a').each(function(index) {
    	$(this).css('backgroundPosition', '-5px ' + bgpos + 'px');
		bgpos = bgpos - 30;
	});

// hide search tip period hack
$('#menu-top-menu li:last a').html(" ");
// chenge bg position to match background graphic
var bgposx = -930 - ($(window).width()-960)/2;
var bgposy = -148;
$('#head_right').css('backgroundPosition', bgposx + 'px ' + bgposy + 'px');
$('#cart_content').css('backgroundPosition', bgposx + 'px ' + (bgposy - 165) + 'px');

$('#sub_links li a').live("mouseenter",
        function(){
            $(this).css({
                'width': '100px'
            });
		}
  
     );


$('#sub_links li a').live("mouseleave",
        function(){
            $(this).css({
                'width': '0px'
            });
		}
  
     );

$('#menu-top-menu li:last a').live("click",
        function(e){
			e.preventDefault();
            $('#search_form').show();
		}
  
     );

// Slide shows

if ($('#findsslider').length > 0){
//	var offset = $('#findsslider').offset();
//alert( "left: " + offset.left + ", top: " + offset.top );
//	$('#findsslider, #about-slider_container').css('width',$(window).width() );
	//$('#findsslider, #about-slider_container').css('height',$(window).height() );
//	$('#findsslider, #about-slider_container').offset('top',0-offset.top)
}

$('#seegal').live("click", function(){
  $('#findsslider, #about-slider_container, #slideclosebtn').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1});
  $('#seemod, #container_finds').css({opacity: 1, visibility: "hidden"}).animate({opacity: 0.0});
});



$('#findsslider, #slideclosebtn').live("click", function(){
										 
	 	if($('#findsslider').css("visibility") == "visible"){
			$('#findsslider, #about-slider_container, #slideclosebtn').css({opacity: 1, visibility: "hidden"}).animate({opacity: 0.0});
			 $('#seemod, #container_finds').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1});
		};
	  
	});

// registration 


$('#voyeur').live("click", function(){									 
	window.location = "http://blackmancruz.com/?page_id=101";	  
});

$('#regdesigner').live("click", function(){	
	window.location = "http://blackmancruz.com/?page_id=2127&bcrole=d";	
});

$('#regcollector').live("click", function(){
	window.location = "http://blackmancruz.com/?page_id=2127&bcrole=c";	
});

$('#cart_icon').live("click", function(){
	window.location = "http://blackmancruz.com/?page_id=5";	
});


$('#tab2_login #wp-submit').live("click", function(e){
	
	if( $('#cimy_uef_p_field_1').is(":visible") && !$("#cimy_uef_1").val() ) {
		
		e.preventDefault();

		alert("must enter valid reseller tax id to register as designer");
		}

	
});

$('div.wpsc_make_purchase input.make_purchase.wpsc_buy_button').live("click", function(e){
	
	if ($(".bctaxid").length > 0 && !$(".bctaxid input").val()) {
		
		e.preventDefault();

		alert("must enter valid reseller tax id to checkout as designer");
		}

	
});

// sign in page functions
if($('#signinrolebtn').length > 0) {
 var tabindex = 1;
    $('input,select').each(function() {
        if (this.type != "hidden") {
            var $input = $(this);
            $input.attr("tabindex", tabindex);
            tabindex++;
        }
    });
}

$('#signinrolebtn').live("click", function(){
	if( $('#cimy_uef_p_field_1').is(":visible") ) {
	  // element is visible
		$("#wp_rar_user_role").val('collector');
		$("#cimy_uef_p_field_1, #cimy_uef_p_field_9, #cimy_uef_p_field_10, #cimy_uef_p_field_11, #cimy_uef_p_field_13, #cimy_uef_p_field_14").hide();
		$("#signinrole").html('Reseller? <span id="signinrolebtn">Sign in as Designer.</span>');
		$("#signinheader").html("Welcome adventurous collector.");
	}
	else {
	  // element is not visible
		$("#wp_rar_user_role").val('designer');
		$("#cimy_uef_p_field_1, #cimy_uef_p_field_9, #cimy_uef_p_field_10, #cimy_uef_p_field_11, #cimy_uef_p_field_13, #cimy_uef_p_field_14").show();
		$("#signinrole").html('Not a reseller? <span id="signinrolebtn">Sign in as Collector.</span>');
		$("#signinheader").html("Welcome adventurous designer.");
	}
			
});





function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

var pageid = getUrlVars()["bcrole"];
var pageid2 = getUrlVars()["page_id"];


if(pageid2=='2127'){
	$("#wp_rar_user_role").val('collector');
	$("#cimy_uef_p_field_1, #cimy_uef_p_field_9, #cimy_uef_p_field_10, #cimy_uef_p_field_11, #cimy_uef_p_field_13, #cimy_uef_p_field_14").hide();
	$("#signinrole").html('Reseller? <span id="signinrolebtn">Sign in as Designer.</span>');
	$("#signinheader").html("Welcome adventurous collector.");
}

if(pageid=='c'){
	$("#wp_rar_user_role").val('collector');
	$("#cimy_uef_p_field_1, #cimy_uef_p_field_9, #cimy_uef_p_field_10, #cimy_uef_p_field_11, #cimy_uef_p_field_13, #cimy_uef_p_field_14").hide();
	$("#signinrole").html('Reseller? <span id="signinrolebtn">Sign in as Designer.</span>');
	$("#signinheader").html("Welcome adventurous collector.");
}
if(pageid=='d'){
	$("#wp_rar_user_role").val('designer');
	$("#cimy_uef_p_field_1, #cimy_uef_p_field_9, #cimy_uef_p_field_10, #cimy_uef_p_field_11, #cimy_uef_p_field_13, #cimy_uef_p_field_14").show();
	$("#signinrole").html('Not a reseller? <span id="signinrolebtn">Sign in as Collector.</span>');
	$("#signinheader").html("Welcome adventurous designer.");
}

// Log in errors
//if ($("#login-register-password").length > 0){

//$("p.error:contains('Invalid username or e-mail')").css('top','318px').css('left','238px');
//$("p.error:contains('The password field is empty.')").css('top','65px').css('left','238px');;
//$("p.error:contains('The username field is empty.')").css('top','65px').css('left','238px');;
//$("p.error:contains('Lost your password.')").css('top','65px').css('left','238px');;
//}

// add lines to separate data on Purchase History
if ($("table.logdisplay.purchasehistory").length > 0){
	
 $(".form_group").after('<div class="formlines"> </div>');
  $("td.details table.customer_details").before('<div class="formlines"> </div>');
}

if ($("#bcaccountprofile").length > 0){
$("td:contains('Country') + td > select").css('width','263');
$("td:contains('Country *') + td > select:last").css('margin-top','10px');
$("td:contains('Country') + td > select:last").css('margin-top','10px');
}


// super picky of me but move add favorites buttonover when in cart
if ($(".bc_productincart").length > 0){
	$("#bcwishlist").css('left','55px');
	
}

if ($("ul.sub-menu").length > 0){
	$("ul.sub-menu").css('width', '100px');
}


$('#cancelbutton').live("click", function(){
	$('#product-enquiry').hide();
	$('p.notice.enquiry').hide();
});

$('#bcproductinquiry').live("click", function(){
	$('p.notice.enquiry').hide();
	$('#product-enquiry').show();
});


// active links on user account page

	if ($("#bcpurchasehistory").length > 0) {$('div.user-profile-links a:contains("Purchase History")').addClass('active');}
	if ($("#bcaccountprofile").length > 0) {$('div.user-profile-links a:contains("Your Details")').addClass('active');}
	if ($("#bcfavorites").length > 0) {$('div.user-profile-links a:contains("Your Favorites")').addClass('active');}

// faqs

$('div.faq').live("click", function(){									 
	$(this).children('div.faqa').toggle(); 
});

// adjust form style
if ($("#bccontactform1").length > 0){
	
	$("#bccontactform1 p:contains('Your Email (required):')").addClass('bccontactformemail');
	$("#bccontactform1 p:contains('Subject:')").addClass('bccontactformsubject');
	$("#bccontactform1 p:contains('Your Message:')").addClass('bccontactformsubject');
	$("#bccontactform1 p:contains('Enter the letters and number combination below:')").addClass('bccontactformsubject');
	
	
}

// layout for product page

if ($("#products_page_container .title").length > 0){

	$("div.producttext").height(260-$("#products_page_container .title").height());
	
	$('#bcbackbutton a').click(function(){
										parent.history.go(-1);
        //parent.history.back();
        return false;
    });
	
}

// add spaces to login button to align with other sublinks

if ($("#sub_links").length > 0){
	
	var currenttxt = $("#sub_links ul li a:contains('Log')").html();
	$("#sub_links ul li a:contains('Log')").html("&nbsp;&nbsp;&nbsp;"+currenttxt);
	
}

// update tax when state changes






}); // end on ready
