var uberWin;
var emailSent   = 'email_sent';
var catalogXSL  = null;
var itemXSL     = null;
var catalogXMLs = new Array();
var itemXMLs    = new Array();

function swap(arg) {
	var my = $(arg);
	
	$$('.selected').each(function(selected) {
		selected.removeClassName('selected');
	});
	$$('.viewport').each(function(viewport) {
		viewport.hide();
	  viewport.removeClassName('showing');
	});
	$(my.parentNode).addClassName('selected');
	$(my.parentNode.id+'-view').show();
	$(my.parentNode.id+'-view').addClassName('showing');
	return false;
}

function video(arg) {
  swap(arg);
}

function onOpenWindow() {
    $$('.video.showing').each(function(showing) {
        showing.hide();
    });
    return true;
}

function onCloseWindow() {
    $$('.video.showing').each(function(showing) {
        showing.show();
    });
    return true;
}

function cswap(arg) {
	var my = $(arg);

	$$('.cselected').each(function(selected) {
		selected.removeClassName('cselected');
	});
	$(my.parentNode).addClassName('cselected');
	$('catalog-viewport').innerHTML = $(my.parentNode.id+'-view').innerHTML;
	return false;
}

function iswap(arg) {
	var my = $(arg);
	
	$$('.iselected').each(function(selected) {
		selected.removeClassName('iselected');
	});
	$(my.parentNode).addClassName('iselected');
	$$('#item-view .viewport').each(function(viewport) {
	  $(viewport).hide();
	})
  $(my.parentNode.id+'-view').show();

  return false;
}

function ivideo(arg) {
  iswap(arg);
}

function getViewHeight() {
	
}

function idoc(link, docId, docKey) {
  if ((docId == null || docId == '') && (docKey == null || docKey == '')) {
    return true;
  }

  var itemDoc = $('itemDocument');
  itemDoc.style.backgroundColor = '#ffffff';
  itemDoc.style.width = '100%';
  itemDoc.style.height = '100%';
  itemDoc.innerHTML = '<div id="docWin-link"><span><a href="javascript://" onclick="return undoc(this);">&lt;&lt; Return to Item</a></span><a href="'+$(link).href+'" target="_blank"><strong>Click here</strong> to download and print this document.</a></div><div id="docWin-ipaper">Document loading...</div>';
  
  var scribd_doc = scribd.Document.getDoc(docId, docKey);
	scribd_doc.write('docWin-ipaper');
	return false;
}

function undoc(arg) {
    var my = $(arg);
    var itemDoc = $(my.parentNode.parentNode.parentNode);
    itemDoc.style.backgroundColor = 'transparent';
    itemDoc.style.width = '0px';
    itemDoc.style.height = '0px';
    itemDoc.innerHTML = '';
    return false;
}

function doc(link, docId, docKey) {
  if ((docId == null || docId == '') && (docKey == null || docKey == '')) {
    return true;
  }
  
	var myViewWidth = 0, myViewHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myViewWidth = window.innerWidth;
    myViewHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myViewWidth = document.documentElement.clientWidth;
    myViewHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myViewWidth = document.body.clientWidth;
    myViewHeight = document.body.clientHeight;
  }
	var myHeight = myViewHeight-40;
	
	uberWin = new Ext.Window({
		id:'docWin',
		title:$(link).innerHTML,
		width:'70%',
    height:myHeight,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<div id="docWin-link"><a href="'+$(link).href+'" target="_blank"><strong>Click here</strong> to download and print this document.</a></div><div id="docWin-ipaper">Document loading...</div>'
	});
  uberWin.addListener('beforeshow', onOpenWindow);
  uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();
	
	var scribd_doc = scribd.Document.getDoc(docId, docKey);
	scribd_doc.write('docWin-ipaper');
	
	return false;
}

function auth_doc(docTitle, docId) {
	var my    = $(arg);
	var parts = $(my.parentNode).id.split('-');
	var myId  = parts[1];
    
  var myViewWidth = 0, myViewHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myViewWidth = window.innerWidth;
    myViewHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myViewWidth = document.documentElement.clientWidth;
    myViewHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myViewWidth = document.body.clientWidth;
    myViewHeight = document.body.clientHeight;
  }
	var myHeight = myViewHeight-40;
	var myWidth  = 750;
	var myFrameWidth = 710;
	var myFrameHeight = 710;

	uberWin = new Ext.Window({
		id:'docWin',
		title:docTitle,
		autoScroll:true,
		width:myWidth,
		height:myHeight,
		layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<iframe src="http://ignite.auctionservices.com/support/auth_document_form/'+myId+'&width='+myFrameWidth+'&height=100%" style="width:100%;height:100%;border:0px" frameborder="0" border="0"></iframe>'
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();

	return false;
}

function cat(node) {
  $('catalog-loading').show();
	var head_tags = document.getElementsByTagName("head");
	var catalogId = node.parentNode.id.split("-")[1];

	if (catalogXMLs[catalogId] == null) {
  	var script_tag = document.createElement("script");
  	script_tag.setAttribute("src", "http://ignite.auctionservices.com/catalogs/"+catalogId+"/callback.js");
  	script_tag.setAttribute("type", "text/javascript");
  	head_tags[0].appendChild(script_tag)
	} else {
	  doCatalogDisplay(catalogId);
	}

	if (itemXSL == null) {
  	var xsl_tag = document.createElement("script");
    xsl_tag.setAttribute("src", "http://ignite.auctionservices.com/item_xsl.js");
    xsl_tag.setAttribute("type", "text/javascript");
    head_tags[0].appendChild(xsl_tag);
	}
  
	return false;
}

function item(node) {
	var head_tags = document.getElementsByTagName("head");
	var itemId = node.parentNode.id.split("-")[1];

	if (itemXMLs[itemId] == null) {
  	var script_tag = document.createElement("script");
  	script_tag.setAttribute("src", "http://ignite.auctionservices.com/items/"+itemId+"/callback.js");
  	script_tag.setAttribute("type", "text/javascript");
  	head_tags[0].appendChild(script_tag)
	} else {
	  doItemDisplay(itemId);
	}
	
	return false;
}

function map(id) {
  var iframe     = '<iframe src="http://ignite.auctionservices.com/auctions/'+id+'/map?width=600&height=440" style="width:600px;height:440px;border:0;overflow:hidden" scrolling="no" border="0" frameborder="0"></iframe>';
  var directions = $('directions-view');
  var output     = '';
  if (directions == null) {
    output = iframe;  
  } else {
    output = directions.innerHTML.replace(new RegExp('%MAP%', 'g'), iframe);
  }

	uberWin = new Ext.Window({
		id:'mapWin',
		title:'Directions/Map',
		autoScroll:true,
		width:650,
		height:550,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:output
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);

	uberWin.show();
	return false;
}

function imap(id) {
  var iframe     = '<iframe src="http://ignite.auctionservices.com/items/'+id+'/map?width=600&height=440" style="width:600px;height:440px;border:0;overflow:hidden" scrolling="no" border="0" frameborder="0"></iframe>';
  var directions = $('item-directions-view');
  var output     = '';
  if (directions == null) {
    output = iframe;  
  } else {
    output = directions.innerHTML.replace(new RegExp('%MAP%', 'g'), iframe);
  }

	uberWin = new Ext.Window({
		id:'mapWin',
		title:'Directions/Map',
		autoScroll:true,
		width:650,
		height:550,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:output
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);

	uberWin.show();
	return false;
}

function print(type, id) {
	window.open('http://ignite.auctionservices.com/print/'+type+'/'+id, 'printScreen', 'width=640,height=480,resizable=no,scrollbars=yes,toolbar=no,location=no,status=no,directories=no,menubar=yes,copyhistory=no');
	return false;
}

function expand(arg) {
	var my = $(arg);

	if ($(my.parentNode).hasClassName('expanded')) {
		Effect.BlindUp($(my.parentNode.id+'-group'));
		$(my.parentNode).removeClassName('expanded')
	} else {
		Effect.BlindDown($(my.parentNode.id+'-group'));
		$(my.parentNode).addClassName('expanded');
	}
	
	return false;
}

function auction_to_a_friend(auction_id, width, height) {
	uberWin = new Ext.Window({
		id:'auction_to_a_friend',
		title:'Send this Auction to a Friend!',
		autoScroll:true,
    width:595,
    height:height+20,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<iframe src="http://ignite.auctionservices.com/support/auction_to_a_friend_form/'+auction_id+'?width=580&height=100%" style="margin:0;padding:0;border:0;width:580px;height:100%" border="0" frameborder="0" onload="if (this.src.match(emailSent)) { uberWin.close(); }"></iframe>'   
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();
	return false;
}

function item_to_a_friend(item_id, width, height) {
	uberWin = new Ext.Window({
		id:'item_to_a_friend',
		title:'Send this Item to a Friend!',
		autoScroll:true,
    width:595,
    height:height+20,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<iframe src="http://ignite.auctionservices.com/support/item_to_a_friend_form/'+item_id+'?width=580&height=100%" style="margin:0;padding:0;border:0;width:580px;height:100%" border="0" frameborder="0" onload="if (this.src.match(emailSent)) { uberWin.close(); }"></iframe>'   
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();
	return false;
}

function contact_employment(employment_id, width, height) {
	uberWin = new Ext.Window({
		id:'contact_employment',
		title:'Contact A Representative',
		autoScroll:true,
    width:595,
    height:height+20,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<iframe src="http://ignite.auctionservices.com/support/contact_employment_form/'+employment_id+'?width=580&height=100%" style="margin:0;padding:0;border:0;width:580px;height:100%" border="0" frameborder="0" onload="if (this.src.match(emailSent)) { uberWin.close(); }"></iframe>'
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();
	return false;
}

function contact_company(company_id, width, height) {
	uberWin = new Ext.Window({
		id:'contact_company',
		title:'Contact Us',
		autoScroll:true,
    width:595,
    height:height+20,
		//layout: 'fit',
		modal:1,
		shadow:1,
		shadowOffset:10,
		html:'<iframe src="http://ignite.auctionservices.com/support/contact_company_form/'+company_id+'?width=580&height=100%" style="margin:0;padding:0;border:0;width:580px;height:100%" border="0" frameborder="0" onload="if (this.src.match(emailSent)) { uberWin.close(); }"></iframe>'   
	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);
	
	uberWin.show();
	return false;
}

function go_to_page(page) {
  $('search_page').value = page;
  $('search_form').submit();
}

function change_per_page(number) {
  $('search_per_page').value = number;
  $('search_form').submit();
}

function search_by_last_initial(initial) {
  $('search_id').value = '';
  $('search_last_initial').value = initial;
  $('search_first_name').value = '';
  $('search_last_name').value = '';
  $('search_company_name').value = '';
  $('search_city').value = '';
  $('search_state_or_country').value = '';
  $('search_radius').value = '';
  $('search_zipcode').value = '';
  $('search_specialty_id').value = '';
 
  $('search_form').submit();
}

function compare_items() {
  var widthConstant = 180;
  var items = new Array();
  $$('.comparable').each(function(chkbox) {
    if (chkbox.checked) 
      items.push(chkbox.value);
  });

  if (items.length > 1) {
   	var myViewWidth = 0, myViewHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
      //Non-IE
      myViewWidth = window.innerWidth;
      myViewHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myViewWidth = document.documentElement.clientWidth;
      myViewHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      //IE 4 compatible
      myViewWidth = document.body.clientWidth;
      myViewHeight = document.body.clientHeight;
    }
  	var myHeight = myViewHeight-40;

   	uberWin = new Ext.Window({
  		id:'item_comparison',
  		title:'Comparing Selected Lots',
      width:widthConstant*items.length+widthConstant,
      height:myHeight,
  		modal:1,
  		shadow:1,
  		shadowOffset:10,
  		html:'<iframe src="http://ignite.auctionservices.com/items/'+items.join(',')+'/compare" style="margin:0;padding:0;border:0;width:100%;height:100%"></iframe>'   
  	});
    uberWin.addListener('beforeshow', onOpenWindow);
    uberWin.addListener('close', onCloseWindow);

  	uberWin.show();
  } else {
    alert('You must select multiple items to compare them!');
  }
 
	return false;
}

function new_search() {
  $('search_id').value = null;
  if ($('search_last_initial') != null) {
    $('search_last_initial').value = null;
  }
  return true;
}

function toggle_advanced_search() {
  var trigger = $('advancedSearchTrigger');
  var fields  = $('advancedSearch');
  if (fields.visible()) {
    new Effect.BlindUp(fields);
    trigger.innerHTML = 'Advanced Search [+]';
  } else {
    new Effect.BlindDown(fields);
    trigger.innerHTML = 'Advanced Search [-]';
  }
  return false;
}

if ($('slider4') != null) {
	Event.observe(window, 'load', function() {
    featuredcontentslider.init({
      id: "slider4",  //id of main slider DIV
      contentsource: ["inline", ""],  //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
      toc: "markup",  //Valid values: "#increment", "markup", ["label1", "label2", etc]
      nextprev: ["", ""],  //labels for "prev" and "next" links. Set to "" to hide.
      revealtype: "mouseover", //Behavior of pagination links to reveal the slides: "click" or "mouseover"
      enablefade: [true, 0.1],  //[true/false, fadedegree]
      autorotate: [true, 3500],  //[true/false, pausetime]
      onChange: function(previndex, curindex){  //event handler fired whenever script changes slide
        //previndex holds index of last slide viewed b4 current (1=1st slide, 2nd=2nd etc)
        //curindex holds index of currently shown slide (1=1st slide, 2nd=2nd etc)
      }
    });
	});
}
Event.observe(window, 'load', function() {
  if (typeof catalog_xsl == 'function') {
    var head_tags = document.getElementsByTagName("head");
    var xsl_tag  = document.createElement("script");
    xsl_tag.setAttribute("src", "http://ignite.auctionservices.com/catalog_xsl.js");
    xsl_tag.setAttribute("type", "text/javascript");
    head_tags[0].appendChild(xsl_tag);
  }
});
