//Array for keeping track if right menu buttons are up or down
var dropPosition = new Array();

function dropActivate(buttonIdent){
	var buttonExpand = buttonIdent+"_expand";
	var buttonShow = buttonIdent+"_show";
	//if up then deploy
	if(!dropPosition[buttonIdent]){
		document.getElementById(buttonExpand).style.height = "auto";
		document.getElementById(buttonShow).style.display = "block";
		dropPosition[buttonIdent] = true;
	}
	//if down rollup
	else{
		document.getElementById(buttonExpand).style.height = "20px";
		document.getElementById(buttonShow).style.display = "none";
		dropPosition[buttonIdent] = false;
	}
}

//used in the animation shiftings
var navCounter = 0;
//which image to start at 0 is the first image
var minImage = 0;
//the maximum images to be displayed
var maxImage = 7;
// used to put the first image in
var keepTracker = true;
//makes sure images are not pushed on first load (IE thing)
var amountCounter = 0;

function imageReplace(image){
	//take the caption of the photo from the alt tag
	if(image.alt){
		var caption = image.alt;
		if(caption.match('Hays Daily News')){
			caption = caption.replace('Hays Daily News', 'Hays Daily News<br />');
		}
	}
	//get the images source
	var image = image.src;
	//remove address from name
	var holder = image.substring(39);
	//where the folder ends
	var index = holder.indexOf('/');
	//extract folder
	var folder = holder.substring(0,index);
	//extract filename
	if(holder.match('thumb_')){
		file = holder.substring(index+7);
	}
	else if(holder.match('_Thumbnail')){
		file = holder.substring(index);
		file = file.replace('_Thumbnail', '_Viewsize');
	}
	else
		file = holder.substring(index);
		
	var clickAction = image.onClick;
	//alert(clickAction);
	
	//chnage the image and the caption
	document.getElementById("top_photo").src = "http://assets.mediaspanonline.com/prod/"+folder+"/"+file;
	if(caption){
	document.getElementById("caption_change").innerHTML = "<p class='cutline'>"+caption+"</p>";
	}
	
	// if this looks stupid then you are using IE!
	//well i mean if you are looking at the code and wonder why the same function would be called twice
	// well you can blame IE.  It did it.
	if(amountCounter > 0){
		getImageInfo(1);
		getImageInfo(-1);
	}
	amountCounter++;
}
var myPopout = "";
function imagePopup(image){

	var imageShow = image.src;
	var imageHeight = parseInt(image.height)+200;
	var imageWidth = parseInt(image.width)+200;
	//var imageHeight= 650;
	//var imageWidth= 650;
	
	var caption = document.getElementById('caption_change').getElementsByTagName('p')[0].innerHTML
	myPopout = window.open("", "imageWindow", "width=500 resizable=1 scrollbars=1");
	myPopout.window.resizeTo(imageWidth,imageHeight);

	popUpWin = myPopout.document
	popUpWin.open();
	popUpWin.writeln("<div align='center' id=\"popimg\">");
	popUpWin.writeln("<img src='"+imageShow+"' />");
	popUpWin.writeln("<p>"+caption+"</p>");
	popUpWin.writeln("<br />");
	popUpWin.writeln("<a href='#' onclick='window.close();'>Close Window</a>");
	popUpWin.writeln("</div>");
	myPopout.focus();
	popUpWin.close();

}

function getImageInfo(newImage){
	// get the image thumbnails and put them in an array
	var something = document.getElementById('animate').getElementsByTagName("img");
	
	// count them
	maxImageAmount = something.length;
	var pointerImage = 0;
	
	if(keepTracker == true){
		imageReplace(something[0]);
		keepTracker = false;
	}
	//add values to move back and foward
	minImage += newImage;
	maxImage += newImage;
	
	//set the display to each thumbnail
	do{
		if(pointerImage >= minImage && pointerImage < maxImage){
			something[pointerImage].style.display = "block";
		}
		else{
			something[pointerImage].style.display = "none";
		}
		pointerImage ++;
	}while(pointerImage < maxImageAmount);
}

function imageLeft(){
	//if not on first image then move backwards
	(minImage > 0) ? getImageInfo(-1) : getImageInfo(0);
}

function imageRight(){
	//if not on last image then move forwards
	(maxImage < maxImageAmount) ? getImageInfo(1) : getImageInfo(0);
}

//this is the dimmensions of the div used to contain the image
var imageResizeWidth = 250;
var imageResizeHeight = 200;

function vAlign(image){
	var imageHeight = image.height;
	var imageWidth = image.width;
	var differenceHeight = (imageResizeHeight - imageHeight)/2;
	var differenceWidth = (imageResizeWidth - imageWidth)/2;
	image.style.padding = differenceHeight+"px "+differenceWidth+"px";
}

	var resizemaybe = true;
function hdnResize(theImage,maxHeight,maxWidth) {
if(resizemaybe) {
	var theThing= document.getElementById(theImage);
    if(theThing.width < maxWidth && theThing.height < maxHeight) {
        theThing.width = maxWidth;
    }
    if(theThing.height >= theThing.width && theThing.height > maxHeight) {
        theThing.height = maxHeight;
       theThing.removeAttribute('width');
    }
    if(theThing.height < theThing.width && theThing.width > maxWidth) {
        theThing.width = maxWidth;
       theThing.removeAttribute('height');
    }
}
}



function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function checkAll(id) {
		var box=document.getElementById(id).getElementsByTagName('input');
		for(i=0; i<box.length; i++) {
			box[i].checked=true;
	}
}

function unCheckAll(id) {
	var box=document.getElementById(id).getElementsByTagName('input');
	for(i=0; i<box.length; i++) {
		box[i].checked=false;
		}
}


// CSS version of resize is down thare, mebbe ie6 likes it? shit no it didnt.
/*function hdnResize(theImage,maxHeight,maxWidth) {
	var theThing= document.getElementById(theImage);
    if(theThing.width < maxWidth && theThing.height < maxHeight) {
        theThing.style.width = maxWidth+"px;";
    }
    if(theThing.height >= theThing.width && theThing.height > maxHeight) {
        theThing.style.height = maxHeight+"px;";
       theThing.style.width = "auto;";
    }
    if(theThing.height < theThing.width && theThing.width > maxWidth) {
        theThing.style.width = maxWidth+"px;";
       theThing.style.height = "auto;";
    }
}
*/
function slideControl(){
	(slideCheck == true) ? slideStop() : slideStart();
}

function slideStart(){
	slideshowStart = setInterval("rotatecontent()", 3000);  //7000
	slideCheck = true;
}

function slideStop(){
	clearInterval(slideshowStart);
	slideCheck = false;
}

//Slide show garbage

if (document.all || document.getElementById){ //if IE4 or NS6+
 document.write('<style type="text/css">\n');
 document.write('.dyncontent{display: none; width: 250px;}\n');
 document.write('</style>');
}

var curcontentindex=0;
var messages=new Array();

function getElementByClass(classname){
 var inc=0;
 var alltags=document.all? document.all : document.getElementsByTagName("*");
 for (i=0; i<alltags.length; i++){
   if (alltags[i].className==classname)
     messages[inc++]=alltags[i];
 }
}

function rotatecontent(){
 //get current message index (to show it):
 curcontentindex=(curcontentindex<messages.length-1)? curcontentindex+1 : 0;
 //get previous message index (to hide it):
 prevcontentindex=(curcontentindex==0)? messages.length-1 : curcontentindex-1;
 messages[prevcontentindex].style.display="none"; //hide previous message
 messages[curcontentindex].style.display="block"; //show current message
vAlign(messages[curcontentindex].getElementsByTagName('img')[0]);
}


// CLASSIFIED PAGE STUFF IS DOWN THARE!

function emailClick()
{
    var theOperator = document.getElementById("actionFormOperator");
    theOperator.value = "message";
    var theForm = document.getElementById("actionForm");
    theForm.action = "/Classifieds/Mail/Sent/";
    theForm.submit();
}

function printClick()
{
    var theOperator = document.getElementById("actionFormOperator");
    theOperator.value = "tag";
    var theForm = document.getElementById("actionForm");
    theForm.action = "/Classifieds/Print/";
    theForm.submit();
}

function basketClick()
{
    var theOperator = document.getElementById("actionFormOperator");
    theOperator.value = "tag";
    var theForm = document.getElementById("actionForm");
    theForm.action = "/Classifieds/Basket/";
    theForm.submit();
}

function clearBasket()
{
    var d = new Date();
    document.cookie = "basket=1;expires=" + d.toGMTString() + ";path=/";
}

function MenuChangeAction(chosen) {

var p = document.searchCategoryForm.ClassificationID;

p.options.length =0;

if ( chosen == "" ) {
		p.options[p.options.length] = new Option('Choose a Subcategory',' ');

	
	}  if ( chosen == "Antiques and Collectibles" )	{
		
	  		p.options[p.options.length] = new Option('Antiques and Collectibles','37');
	  	

}  if ( chosen == "Apartments for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Apartments for Rent','79');
	  	
		
}  if ( chosen == "Auto Parts and Accessories" )	{
		
	  		p.options[p.options.length] = new Option('Auto Parts & Accessories','66');
	  	
		
}  if ( chosen == "Automobiles" )	{
		
	  		p.options[p.options.length] = new Option('Automobiles for Sale','65');
	  	
	  		p.options[p.options.length] = new Option('Classic Automobiles','70');
	  	
	  		p.options[p.options.length] = new Option('Sport & Utility Vehicles','63');
	  	
	  		p.options[p.options.length] = new Option('Trucks for Sale','67');
	  	
	  		p.options[p.options.length] = new Option('Vans Mini Conversion','64');
	  	
		
}  if ( chosen == "Boats Trailers Water Equipment" )	{
		
	  		p.options[p.options.length] = new Option('Boats Trailers Water Equipment','38');
	  	
		
}  if ( chosen == "Business Bldgs. for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Business Bldgs. for Rent','81');
	  	
		

}  if ( chosen == "Business Locations" )	{
		
	  		p.options[p.options.length] = new Option('Business Locations','91');
	  	

}  if ( chosen == "Business Opportunity" )	{
		
	  		p.options[p.options.length] = new Option('Business Opportunity','96');
	  	

}  if ( chosen == "Campers and Camping Trailers" )	{
		
	  		p.options[p.options.length] = new Option('Campers Camping Trailers','68');
	  	

}  if ( chosen == "Childcare Services" )	{
		
	  		p.options[p.options.length] = new Option('Childcare Services','15');
	  	
 
}  if ( chosen == "Computer Electronics" )	{
		
	  		p.options[p.options.length] = new Option('Computers Electronics','31');
	  	


}  if ( chosen == "Connections" )	{
		

}  if ( chosen == "Events" )	{
		
	  		p.options[p.options.length] = new Option('Events','9');
	  	
		
}  if ( chosen == "Farm Equipment" )	{
		
	  		p.options[p.options.length] = new Option('Farm Equipment','53');
	  	
		
}  if ( chosen == "Farm Houses for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Farm Houses for Rent','83');
	  	
		
}  if ( chosen == "Farms and Tracts for Sale" )	{
		
	  		p.options[p.options.length] = new Option('Farms & Tracts for Sale','94');
	  	
		
}  if ( chosen == "Feed Hay and Grain" )	{
		
	  		p.options[p.options.length] = new Option('Feed Hay & Grain','50');
	  		

}  if ( chosen == "Firewood for Sale" )	{
		
	  		p.options[p.options.length] = new Option('Firewood for Sale','47');
	  	

}  if ( chosen == "Fitness Equipment" )	{
		
	  		p.options[p.options.length] = new Option('Fitness Equipment','34');
	  	

}  if ( chosen == "Food and Produce" )	{
		
	  		p.options[p.options.length] = new Option('Food and Produce','40');
	  	

}  if ( chosen == "For Rent or Sale" )	{
		
	  		p.options[p.options.length] = new Option('For Rent or Sale','84');
	  	
 
 }  if ( chosen == "For Sale by Owner" )	{
		
	  		p.options[p.options.length] = new Option('For Sale by Owner','98');
	  	
}
	if ( chosen == "Furniture and Appliances" )	{
		
	  		p.options[p.options.length] = new Option('Furniture and Appliances','41');
	  	
}
	if ( chosen == "Garage Sales" )	{
		
	  		p.options[p.options.length] = new Option('Garage Sales','11');
	  	
}
	if ( chosen == "Guns Sporting Goods" )	{
		
	  		p.options[p.options.length] = new Option('Guns Sporting Goods','39');
	  	
}
	if ( chosen == "Help Wanted" )	{
		
	  		p.options[p.options.length] = new Option('Construction Laborers Wanted','23');
	  	
	  		p.options[p.options.length] = new Option('Drivers Wanted','18');
	  	
	  		p.options[p.options.length] = new Option('General Help Wanted','20');
	  	
	  		p.options[p.options.length] = new Option('Medical Help Wanted','19');
	  	
	  		p.options[p.options.length] = new Option('Motel Restaurant Help Wanted','17');
	  	
	  		p.options[p.options.length] = new Option('Office Help Wanted','22');
	  	
	  		p.options[p.options.length] = new Option('Sales Help Wanted','16');
	  	
}
	if ( chosen == "Houses and Lots" )	{
		
	  		p.options[p.options.length] = new Option('Houses and Lots','92');
	  	
}
	if ( chosen == "Houses for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Houses for Rent','78');
	  	
}
	if ( chosen == "Investment and Business Property" )	{
		
}
	if ( chosen == "Land for Lease" )	{
		
	  		p.options[p.options.length] = new Option('Land for Lease','55');
	  	
}
	if ( chosen == "Lawn and Garden Supplies" )	{
		
	  		p.options[p.options.length] = new Option('Lawn & Garden Supplies','44');
	  	
}
	if ( chosen == "Livestock and Supplies" )	{
		
	  		p.options[p.options.length] = new Option('Livestock & Supplies','52');
	  	
}
	if ( chosen == "Lost Found Strayed" )	{
		
	  		p.options[p.options.length] = new Option('Lost Found Strayed','12');
	  	
}
	if ( chosen == "Misc. Animals and Supplies" )	{
		
	  		p.options[p.options.length] = new Option('Misc. Animals Supplies','51');
	  	
}
	if ( chosen == "Miscellaneous Merchandise" )	{
		
	  		p.options[p.options.length] = new Option('Miscellaneous Merchandise','46');
	  	
}
	if ( chosen == "Miscellaneous Real Estate" )	{
		
	  		p.options[p.options.length] = new Option('Miscellaneous Real Estate','97');
	  	
}
	if ( chosen == "Miscellaneous Rentals" )	{
		
	  		p.options[p.options.length] = new Option('Miscellaneous Rentals','85');
	  	
}
	if ( chosen == "Modular Homes and Lots" )	{
		
	  		p.options[p.options.length] = new Option('Modular Homes and Lots','93');
	  	
}
	if ( chosen == "Modular Homes for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Modular Homes for Rent','87');
	  	
}
	if ( chosen == "Motorcycles Bicycles ATVs" )	{
		
	  		p.options[p.options.length] = new Option('Motorcycles Bicycles ATVs','69');
	  	
}
	if ( chosen == "Musical Instruments" )	{
		
	  		p.options[p.options.length] = new Option('Musical Instruments','43');
	  	
}
	if ( chosen == "Office Business Equipment" )	{
		
	  		p.options[p.options.length] = new Option('Office Business Equipment','35');
	  	
}
	if ( chosen == "Offices for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Offices for Rent','82');
	  	
}
	if ( chosen == "Oil Field Leases and Equipment" )	{
		
	  		p.options[p.options.length] = new Option('Oil Field Leases & Equipment','32');
	  	
}
	if ( chosen == "Personal Connections" )	{
		
	  		p.options[p.options.length] = new Option('Personal Connections','10');
	  	
}
	if ( chosen == "Pets and Supplies" )	{
		
	  		p.options[p.options.length] = new Option('Pets & Supplies','45');
	  	
}
	if ( chosen == "Public Auctions" )	{
		
	  		p.options[p.options.length] = new Option('Public Auctions','29');
	  	
}
	if ( chosen == "Real Estate for Rent" )	{
		
}
	if ( chosen == "Real Estate for Sale" )	{
		
}
	if ( chosen == "Real Estate Wanted" )	{
		
	  		p.options[p.options.length] = new Option('Real Estate Wanted','90');
	  	
}
	if ( chosen == "Roommates Wanted" )	{
		
	  		p.options[p.options.length] = new Option('Roommates Wanted','74');
	  	
}
	if ( chosen == "Schools and Pre-Schools" )	{
		
	  		p.options[p.options.length] = new Option('Schools and Pre-Schools','14');
	  	
}
	if ( chosen == "Situations Wanted" )	{
		
	  		p.options[p.options.length] = new Option('Situations Wanted','21');
	  	
}
	if ( chosen == "Special Notices" )	{
		
	  		p.options[p.options.length] = new Option('Special Notices','13');
	  	
}
	if ( chosen == "Special Services" )	{
		
	  		p.options[p.options.length] = new Option('Special Services','28');
	  	
}
	if ( chosen == "Storage Units for Rent" )	{
		
	  		p.options[p.options.length] = new Option('Storage Units for Rent','73');
	  	
}
	if ( chosen == "Tickets Resorts Vacations" )	{
		
	  		p.options[p.options.length] = new Option('Tickets Resorts Vacations','33');
	  	
}
	if ( chosen == "Time Shares" )	{
		
	  		p.options[p.options.length] = new Option('Time Shares','99');
	  	
}
	if ( chosen == "Tools Building Materials" )	{
		
	  		p.options[p.options.length] = new Option('Tools Building Materials','36');
	  	
}
	if ( chosen == "Trailers for Sale" )	{
		
	  		p.options[p.options.length] = new Option('Trailers for Sale','71');
	  	
}
	if ( chosen == "Wanted to Buy" )	{
		
	  		p.options[p.options.length] = new Option('Wanted to Buy','30');
	  	
}
	if ( chosen == "Wanted to Rent" )	{
		
	  		p.options[p.options.length] = new Option('Wanted to Rent','75');
	  	
}}