function swapImg(img, src) {
	$(img).src = src;
}

function addtocart(pid) {
	jsf = new JSF(); 
	jsf.createField('action', 'addtocart'); 
	jsf.createField('pid', pid); 
	jsf.submitForm();
	return false;
}

function deletecart(pid) {
	jsf = new JSF(); 
	jsf.createField('action', 'deletecart'); 
	jsf.createField('pid', pid); 
	jsf.submitForm();
	return false;
}

function center_with_autoscroll() { 
	/*if(Prototype.Browser.IE) { 
		$('outergrid').style.display = ''; 
		return; 
	}*/
	
	$('outergrid').style.display = 'none';
	$('outergrid').style.position = 'absolute';
	
	if(document.viewport.getWidth() > 1020) {
		$('outergrid').style.left = (((document.viewport.getWidth() - 1020) / 2) - 8)+"px";
	} else {
		$('outergrid').style.left = "0px";
	}
	
	$('outergrid').style.display = '';
}

function float_footer(func) { 
	if($('footer')) 
		$('footer').remove();
		
	$(document.body).insert('<div id="footer">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; 2009 LadyB.com </div>');
	
	$('footer').style.position = 'absolute';
	$('footer').style.left = $('outergrid').style.left;
	
	var scrolloff = document.viewport.getScrollOffsets();
	
	if($('outergrid').getHeight() < document.viewport.getHeight()) {
		$('footer').style.top = (document.viewport.getHeight() + scrolloff[1] - 30)+"px";
	} else {
		
		$('footer').style.top = ($('outergrid').getHeight())+"px";
		$('footer').style.height = "30px";
	}
	
	//$('footer').insert($('outergrid').getHeight()+' < '+document.viewport.getHeight());
	//$('footer').insert($('footer').style.top); 
	//$('footer').style.border = "1px solid #ccc";
}

function iniZoomSWF(imgSmall, imgLarge) { 
	/*
	var patt = new RegExp(/^http:\/\/ladyb\.com\//);
	var patt_www = new RegExp(/^http:\/\/www\.ladyb\.com\//);

	if( imgSmall.search(patt) == -1 ) {
		imgSmall = "http://ladyb.com/"+imgSmall;
	}
	
	if( imgLarge.search(patt) == -1 ) {
		imgLarge = "http://ladyb.com/"+imgLarge;
	}
	*/
	

	if(window.console) { //
		//console.log( imgSmall.search(patt), imgSmall.search(patt_www), imgSmall );
		//console.log( imgLarge.search(patt), imgLarge.search(patt_www), imgLarge );
		console.log( imgSmall );
		console.log( imgLarge );
		console.log( " " );
		t = imgSmall.split('/');
		console.log( t[ (t.length - 2) ], t );
	}
	
	
	if( $('zoomSWF') ) {
		$('zoomSWF').innerHTML = '';
		$('zoomsg').style.visibility = 'hidden';
		
		$('zoomcolor').innerHTML = '';
			var zoco = imgSmall.split('/');
		$('zoomcolor').innerHTML = decodeURI(zoco[ (zoco.length - 2) ]);
			
		if( imgSmall.search(/detail/gi) != -1) {
			$('zoomSWF').insert( '<img src="'+ encodeURI(imgSmall) +'" />' );
			console.log( "detail", imgSmall.search(/detail/gi), imgSmall );
			return;
		}
	
		if (AC_FL_RunContent == 0) {
				alert("This page requires AC_RunActiveContent.js.");
		} else {
			var acswf = AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
				'width', '256',
				'height', '460',
				'src', 'swf/zoomv3?small='+imgSmall+'&large='+imgLarge,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'swf_zoomv3',
				'bgcolor', '#ffffff',
				'name', 'swf_zoomv3',
				'menu', 'true',
				'allowFullScreen', 'false',
				'allowScriptAccess','sameDomain',
				'movie', 'includes/swf/zoomv3?small='+imgSmall+'&large='+imgLarge,
				'salign', ''
			); //end AC code
		}
		
		//alert(acswf);
		$('zoomSWF').insert( acswf ); //$('zoomSWF').innerHTML = acswf;
		$('zoomsg').style.visibility = 'visible';
	}
	
	return false;
}

window.onload = function () {
	center_with_autoscroll();
	float_footer('onload');
	
	if( $('zoomSWF') ) { // grab src of init-image and pass as param to start zoomSWF
		/*if(window.console) {
			console.log( $('zoomSWF').down().src );
			console.log( $('zoomSWF').down().readAttribute("zoomin") );
			console.log( " " );
		}*/
		iniZoomSWF( $('zoomSWF').down().src, $('zoomSWF').down().readAttribute("zoomin") );
	}
};



window.onresize = function () {
	center_with_autoscroll();
	float_footer('onresize');
};
