use("thing.unroll");

//global variables
gProdImgArray = new Array();
gProdDescArray = new Array();
gCurProd = 0;

function openSlider(){
	//get current location
	whereWasI = window.location.href;
	mycookie = 'whereWasI=' + escape(whereWasI) + '; path=/Imaging_World/';
	document.cookie = mycookie;
	
	if( is.mac ) location.href = '/Imaging_World/';
	else goToImgWorld();
}

function closeSlider(){
	whereWasI = getCookie('whereWasI');
	if(whereWasI) newLocation = whereWasI;
	else newLocation = '/';
	if( is.mac ) location.href  = newLocation;
	else goToSite(newLocation);
}

function goToSite(newLocation){
	//first hide photographer drop-down so it doesn't show through
	document.getElementById('photoDropdownDiv').style.visibility = 'hidden';

	sliderScreen.unroll( 40, 0, 2 );
	sliderScreen.onUnrollEnd = function(){
		//unhide product dropdowns
		dropdowns = document.getElementById('productDropdownDiv');
		if(dropdowns){
			dropdowns.style.visibility = 'visible';
		}
		
		location.href = newLocation;
	}
}
function goToImgWorld(){
	//first hide product drop-downs so they don't show through
	dropdowns = document.getElementById('productDropdownDiv');
	if(dropdowns){
		dropdowns.style.visibility = 'hidden';
	}
	
	productFinderButton.hide();
	sliderBar.hide();
	sliderScreen.unroll( -40, 0, 2 );
	sliderScreen.onUnrollEnd = function(){
		location.href = '/Imaging_World/';
	}
}

function changeProduct( direction ) {
	if(direction == 'right'){
		gCurProd++;
	}
	else{
		gCurProd--;
		if(gCurProd < 0) gCurProd = gProdImgArray.length - 1;
	}
	gCurProd = gCurProd % gProdImgArray.length;
}

function checkForProdFinderPage() {
	myLocation = window.location.href;
	if(myLocation.match(/pf=1/)){
		showProdFinder();
	}
}
window.name = 'lowepro';
function showProdFinder(){
	if( is.mac && is.ie ){		
		productFinderWin = window.open( '/ProductFinder/', 'productFinderWin', 'width=476,height=390' );
		if( productFinderWin ){
			productFinderWin.focus();
		}
	}
	else{
		// first hide product drop-downs so they don't show through
		dropdowns = document.getElementById('productDropdownDiv');
		if(dropdowns){
			dropdowns.style.visibility = 'hidden';
		}
		document.getElementById('prodFinderScreen').style.visibility = 'visible';
		document.getElementById('prodFinderNext').style.visibility = 'visible';
		document.getElementById('prodFinder').style.left = 150;
		document.getElementById('prodFinder').style.visibility = 'visible';		
	}
	
	
}

function closeProdFinderWithButton() {
	location.search='';
}

function closeProdFinder() {
	document.getElementById('prodFinder').style.left = -1000;
	document.getElementById('prodFinder').style.visibility = 'hidden';
	document.getElementById('prodFinderNext').style.visibility = 'hidden';
	document.getElementById('prodFinderScreen').style.visibility = 'hidden';

	//unhide product dropdowns
	dropdowns = document.getElementById('productDropdownDiv');
	if(dropdowns){
		dropdowns.style.visibility = 'visible';
	}
}

function resizeWindow(y) {
	document.getElementById('prodFinderWin').height = y;
	document.getElementById('prodFinder').height = y;
}

function getCookie(name) {
	myCookie = document.cookie;
	index = myCookie.indexOf(name + "=");
	if (index == -1) return null;
	index = myCookie.indexOf("=", index) + 1;
	var endstr = myCookie.indexOf(";", index);
	if (endstr == -1) endstr = myCookie.length;
	return unescape(myCookie.substring(index, endstr));
}

function printRow(){
	var html = '';
	if( window.print != undefined ){
		html = '<tr><td class="LMenuPrint"><img src="/images/pixel.gif" width="14" height="24" border="0" alt="" /></td><td><img src="/images/pixel.gif" width="1" height="1" border="0" alt="" /></td><td class="LMenuPrint"><a href="#" onclick="window.print(); return false;"><img src="/images/print.gif" width="22" height="24" border="0" alt="Wydrukuj strone" align="absmiddle" />Wydrukuj strone</a></td></tr>';
	}
	return html;
}

function replace(string,text,by) {
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength) newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function fixLinks(){
	for( var i=0; i<document.links.length; i++ ){
		var link = document.links[i];
		if( link.href.replace( "http://" + location.host, "" ).indexOf( "http" ) == 0 ){
			link.target = "outside";
		}
	}
}
init("fixLinks()");
