// ---	preload navigation rollovers
arrImg 	= new Array ( 	"about-grey_on.gif", 		"press-grey_on.gif", 	"jewelry-grey_on.gif", 
			"red_carpet-grey_on.gif", 	"shop-grey_on.gif", 	"stylist-grey_on.gif", 
			"blog-grey_on.gif", 		"contact-grey_on.gif", 	"log_in-grey_on.gif", 
			
			"about-on.png", 		"press-on.png", 	"jewelry-on.png", 
			"red_carpet-grey_on.png", 	"shop-grey_on.png", 	"stylist-on.png", 
			"blog-on.png", 			"contact-on.png", 	"log_in-on.png", 
			
			"home-grey_on.gif", 		"trunk_show-grey_on.gif", 	"shopping_bag-grey_on.gif", 	"search-grey_on.gif", 	"collections-grey_on.gif", 
			"home-on.png", 			"trunk_show-on.png", 		"shopping_bag-on.png", 		"search-on.png", 	"collections-on.png" 
			);
for ( i in arrImg ) {
	var tmpImg 	= new Image ();
	tmpImg.src 	= "http://www.houseoflavande.com/shopify/nav/" + arrImg[ i ];
}
	
// ---	parse querystring into global array: ?name=value :: arr_qs[ name ] = value
var arr_parse 	= top.location.search.substr ( 1 ).split ( "&" );
var arr_qs 		= new Array ();
for ( k in arr_parse ) {
	var arr_tmp 	= arr_parse[ k ].split ( "=" );
	arr_qs[ arr_tmp[ 0 ] ] 	= arr_tmp[ 1 ];
}

function begin () {
	//alert ( 'begin ()' );
	set_bleed ();
	document.getElementById ( 'preloader' ).style.display 	= 'none';
}
function set_bleed () {
	//alert ( 'set_bleed ()' );
	var o_img 		= document.getElementById ( 'bleed_img' );
	var img_w 		= o_img.offsetWidth;
	var img_h 		= o_img.offsetHeight;
	
	var o_bleed 	= document.getElementById ( 'bleed' );
	var bleed_w 	= o_bleed.offsetWidth;
	var bleed_h 	= o_bleed.offsetHeight;
	
	var img_ratio 	= img_h / img_w;
	var new_h 		= Math.ceil ( bleed_w * img_ratio );
	var new_x 		= 0;
	var new_y 		= 0;
	if ( bleed_h > new_h ) {
		// ---	set the image to bleed horizontally
		img_ratio 	= img_w / img_h;
		o_img.style.width 	= Math.ceil ( bleed_h * img_ratio ) + "px";
		o_img.style.height 	= bleed_h + "px";
		// ---	center align
		var new_x 	= Math.ceil ( - ( ( o_img.offsetWidth - o_bleed.offsetWidth ) /2 ) );
	} else {
		// ---	set the image to bleed vertically
		o_img.style.width 	= bleed_w + "px";
		o_img.style.height 	= new_h + "px";
		// ---	middle align
		var new_y 	= Math.ceil ( - ( ( o_img.offsetHeight - o_bleed.offsetHeight ) /3 ) );
	}
	o_img.style.marginLeft 	= new_x + "px";
	o_img.style.marginTop 	= new_y + "px";
}

// ---	flyout menus
function show_flyout ( id ) {
	hide_flyouts ();
	document.getElementById ( 'flo_' + id ).style.display 		= 'block';
}
function hide_flyouts () {
	document.getElementById ( 'welcome_note' ).style.display 		= 'none';
	document.getElementById ( 'flo_search' ).style.display 			= 'none';
	document.getElementById ( 'flo_collections' ).style.display 	= 'none';
}
// ---	iframe pages
function show_page ( url ) {
	pg_ifr 		= document.getElementById ( "page_ifr" );
	pg_cont 	= document.getElementById ( "page_container" );
	pg_ifr.src 	= url;
	pg_cont.style.display 	= 'block';
}
function close_page () {
	top.document.getElementById( "page_ifr" ).src 	= "";
	top.document.getElementById ( "page_container" ).style.display 	= 'none';
}
// ---	iframe product
var curr_url 		= arr_qs[ 'LVU' ];
var curr_handle 	= arr_qs[ 'LVH' ];
var curr_enl 		= arr_qs[ 'LVE' ];
var pg_qs;
function set_product ( url, handle, enl_img ) {
	//alert ( "set_product ( url:" + url + ", handle:" + handle + ", enl_img:" + enl_img + " )" );
	// ---	set the product in the iframe
	pg_prod 		= document.getElementById ( "prod_ifr" );
	pg_prod.src 	= url;
	// ---	turn off the previous thumb
	if ( curr_handle && document.getElementById ( 'tn_' + curr_handle ) ) {
		document.getElementById ( 'tn_btn_' + curr_handle ).style.display 	= 'block';
		document.getElementById ( 'tn_' + curr_handle ).className 			= 'thumbnail';
	}
	// ---	set selected thumb
	if ( document.getElementById ( 'tn_' + handle ) ) {
		document.getElementById ( 'tn_btn_' + handle ).style.display 	= 'none';
		document.getElementById ( 'tn_' + handle ).className 			= 'thumbnail thumb_on';
	}
	// ---	set enlarged image
	document.getElementById ( 'enl_img' ).src 		= enl_img;
	// ---	set global vars
	curr_url 		= url;
	curr_handle 	= handle;
	curr_enl 		= enl_img;
	pg_qs 			= '&LVU=' + curr_url + '&LVH=' + curr_handle + '&LVE=' + curr_enl;
}
function remove_item ( id ) {
  document.getElementById ( 'updates_' + id ).value 	= 0;
  document.getElementById ( 'cartform' ).submit ();
}

