//=======================================================================================================
//-------------------------------------------------------------------------------------------------------
//	Custom Javascript functions
//-------------------------------------------------------------------------------------------------------
//=======================================================================================================



//-------------------------------------------------------------------------------------------------------
//	Gallery js functions
//-------------------------------------------------------------------------------------------------------

function changeimage(img,title,idx)
{
	if( document.getElementById )
	{
		document.getElementById('photocaption').innerHTML = title; 
		obj	= document.getElementById('mainimage');
		obj.setAttribute( 'src', img );
	}
}




//-------------------------------------------------------------------------------------------------------
//	Other custom Javascript functions
//-------------------------------------------------------------------------------------------------------




group_id = 1;

/*
var	newrules = {
	'.group1':
	{
		onmouseover	: function() { gridtest( this, 1 ) },
		onmouseout	: function() { gridtest( this, 1 ) }
	},

	'.group2':
	{
		onmouseover	: function() { gridtest( this, 2 ); },
		onmouseout	: function() { gridtest( this, 2 ); }
	}
};

Behavior.register(newrules);
*/

fades	= new Array();
start	= new Array();

	start		= 0.0;
	end			= 1.0;
	interval	= 0.05;


fade_objects	= new Array();
obj_index	= 0;


//	used for settimeout func
opacities	= new Array();

dostuff( '.group1', 1000 );
dostuff( '.group2', 3000 );



function dostuff( group_id, init_delay )
{
	objects	= document.getElementsBySelector( group_id );

	for( i = 0; i < objects.length; i++ )
	{
		fade_objects[ obj_index ]	= objects[i];

		id	= fade_objects[ obj_index ].getAttribute( "id" );
		id	= parseInt( id.substring( id.length -2, id.length ));
		start[id]	= setTimeout( "startfade2( fade_objects[" + obj_index + "]," + obj_index + " );", init_delay );
		obj_index++;
	}
}




function startfade2( object, obj_index )
{
	
	id	= object.getAttribute( "id" );
	id	= parseInt( id.substring( id.length -2, id.length ));

	fades[id]	= setInterval( "dofade( fade_objects[" + obj_index + "], 0 );", 20 );
	clearTimeout( start[id] );
}

function dofade( object )
{
	id	= object.getAttribute( "id" );
	id	= parseInt( id.substring( id.length -2, id.length ));

	if( !opacities[id] || opacities[id] == "NaN" )
	{
		opacities[id]	= interval;
	}
	else
	{
		opacities[id]	+= interval;
	}

	opacityvalue	= opacities[id];

	if( opacityvalue > 1 - interval )
	{
		opacityvalue	= 1;
		clearInterval( fades[id] );
	}

	//	Change opacity
	object.style.opacity	= opacityvalue;

	//	Change opacity (IE hack)
	object.style.filter	= "progid:DXImageTransform.Microsoft.Alpha(opacity=" + parseInt( opacityvalue * 100 ) + ")";
}

function toggleDiv( div_id )
{
	current_div.style.display = 'none';
	current_div = document.getElementById( div_id );
	current_div.style.display = 'block';
}

function make_links_inactive()
{
	table_element = document.getElementById('thumb_product_table');
	elements	= table_element.getElementsByTagName('a');

	element_length = elements.length;
	//alert( element_length );

	for (var i=0; i< element_length; i++) 
	{
		//elements[i].onmouseover = function(){return true;};
		elements[i].onmouseover = null;
		//elements[i].removeAttribute('onmouseover');
	}
}

function updateSample(obj)
{
//	alert( obj.checked +' x '+obj.value);
/*	$.ajaxSetup({
	url: "/wishlist/update-sample.php",
	global: false,
	type: "POST"
	});
	$.ajax({ product_id: obj.value,sample: obj.checked  });
*/
var sample = obj.checked ? 1 : 0;
	$.get("/wishlist/update-sample.php", { 'product_id': obj.value, 'sample': sample } );

}


function show_color(prod_id, shape_id)
{
	var div				= '#sizes_'+prod_id ;
	var all_rows		= div +' tr.product_row';
	var active_rows		= div +' tr.shape_'+shape_id;
	var active_link		= '#link_'+prod_id +'_'+shape_id;
	
	//alert($(all_rows));
	
	$(all_rows).hide();
	$(active_rows).show();
	
	$(div +' .active_link').toggleClass('active_link');
	$(active_link).toggleClass('active_link');
}