/* -- Adobe GoLive JavaScript Library */
/* -- Global Functions */
CSStateArray = new Object;
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
}
function toggleImages() {
	for (var i=0; i<toggleImages.arguments.length; i+=2) {
		if (selected == toggleImages.arguments[i])
			changeImagesArray(toggleImages.arguments[i+1]);
	}
}
/* -- Action Functions */
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]; 
}
CSImages=new Array();
function CSPreloadImage(action) {
	if (document.images) { CSImages[CSImages.length]=new Image(); CSImages[CSImages.length-1].src=action[1]; }
}
function ROPreloadURL (act) {
	ROPreloadURLArray[ROPreloadURLArray.length]=act[1];
}
ROPreloadURLArray=new Array();
function RPOnPreload() {	/* RO-Event-Handler */
	for(var i=0;i<ROPreloadURLArray.length;i++) {
		if (ROPreloadURLArray[i] != 0) {
			window.parent.external.PreloadURL(ROPreloadURLArray[i]);
			ROPreloadURLArray[i]=0;
		}
	}
}
function CSSetImageURL(action) {
	var img=CSGetImage(action[1]);
	if (img) img.src=action[2];
}
function setSize(){
	var pName = document.forms['buy'].elements['amount'];
	var sSize = document.forms['buy'].elements['p_size'].value;
	if (sSize == '5x7') pName.value = '5.00';
	if (sSize == '8x10') pName.value = '10.00';
	if (sSize == '16x20') pName.value = '35.00';
}

//Preview handling
function openWindow(fileName, photoName, photoCat, photoDescription){
	var previewWindow = window.open('','previewWindow','height=500,width=500,resizable=yes');
	//previewWindow.document.write("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01//EN'>");
	previewWindow.document.write("<head><title>");
	previewWindow.document.write(photoName);
	previewWindow.document.write("</title>");
	previewWindow.document.write("<link href='http://www.ccsgraphic.com/style.css' rel='stylesheet' type='text/css' media='all'><csscriptdict import><script type='text/javascript' src='http://www.ccsgraphic.com/CSScriptLib.js'></script>	</csscriptdict></head><body class='preview'>");
	previewWindow.document.write("<div class='titlehead'>");
	previewWindow.document.write(photoName);
	previewWindow.document.write("</div>");
	previewWindow.document.write("<div style='size: 100%;'><object class='preview'><param name='wmode' value='transparent'><param name='bgcolor' value='#368cbf'><param name='movie' value='/images/Previews/");
	previewWindow.document.write(fileName);
	previewWindow.document.write(".swf' width='100%' height='100%'><embed class='preview' wmode='transparent' bgcolor='#368cbf' src='/images/Previews/");
	previewWindow.document.write(fileName);
	previewWindow.document.write(".swf' width='100%' height='100%'></embed></object></div>");
	previewWindow.document.write("<br>Category: " + photoCat + "<br>");
	previewWindow.document.write("<div class='pdescription'>");
	previewWindow.document.write(document.getElementById(photoDescription).innerHTML);
	previewWindow.document.write("<span class='store_button'><form name='buy' action='https://www.paypal.com/cgi-bin/webscr' method='post'>Quantity: <input name='add' size='2' value='1'><input type='hidden' name='cs' value='368CBF'><input type='hidden' name='cmd' value='_cart'><input type='hidden' name='business' value='ccsccs7@yahoo.com'><input type='hidden' name='item_name' value='" + photoName + "'><input type='hidden' name='amount' value='10.00'><input type='hidden' name='no_note' value='1'><input type='hidden' name='currency_code' value='USD'>	Size: <select name='p_size' onChange='setSize();'><option value='5x7'>5 x 7 - $5</option><option value='8x10'  selected='selected'>8 x 10 - $10</option><option value='16x20'>16 x 20 - $35</option></select><input type='image' name='submit' src='http://www.ccsgraphic.com/images/buyprint.gif' border='0' alt='Make payments with PayPal - it's fast, free and secure!'></form></span></div>");
	previewWindow.document.write("</body></html>");
	previewWindow.document.close();
	previewWindow.focus();

}

//MENUS
var menuNames = new Array('Portfolio','Services','Software','Store');
var tempItem;
function openMenu(menuName){
		for(i=0; i < menuNames.length; i++){
			tempItem = getItem(menuNames[i]);
			closeMenu(tempItem);
			tempItem = getItem(menuNames[i] + "_dot");
			menuDot(tempItem);
		}
		
		tempItem = getItem(menuName);
		tempItem.style.visibility = ("visible");
		tempItem.style.height = ("auto");
		tempItem.style.display = ("block");
		tempItem = getItem(menuName + "_dot");
		tempItem.src = ("images/spot.png");
	}
	
	function closeMenu(menuName){
		menuName.style.visibility = ("hidden");
		menuName.style.height = ("0px");
		menuName.style.display = ("none");
		menuName.style.overflow = ("hidden");
	}
	
	function menuDot(dotName){
		dotName.src = ("images/dot.png");
	}
	
	function getItem(itemName){
		returnItem = document.getElementById(itemName);
		return returnItem;
	}
	
	function openContent(contentID){
		tempItem = getItem(contentID);
		if(tempItem.style.visibility  == "visible"){
			closeContent(contentID);
			
		} else{
			tempItem.style.visibility = ("visible");
			tempItem.style.display = ("block");
		}
	}
	function closeContent(contentID){
		tempItem = getItem(contentID);
		tempItem.style.visibility = ("hidden");
		tempItem.style.display = ("none");
	}
//AJAX Contact form
function submitForm(){
	formItem = document.getElementById("fEmail");
	formEmail = formItem.value;
	formItem = document.getElementById("fMessage");
	formMessage = formItem.value;
	formItem = document.getElementById("contactPage");
	formPage = formItem.value;
//Handle validation etc here.
	sendMessage(formEmail, formMessage);
}
function sendMessage(formEmail, formMessage){
  var xmlHttp;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e){
      try{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e){
        alert("Your browser does not support AJAX!");
        //possibly do some cool automatic form submittal to get a new page.
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function(){
  if(xmlHttp.readyState==4){
  	contactDiv = document.getElementById("contactContent");
    contactDiv.innerHTML=(xmlHttp.responseText);
    }
  }
  var sendString;
  sendString = "email=" + formEmail + "&message=" + formMessage + "&page=" + formPage + "&ajax=true";
  //document.write(sendString);
  xmlHttp.open("POST","contact.php",true);
  xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.send(sendString);
 }
 
//Contact form submit page
function currentPage(){
	formField = document.getElementById("contactPage");
	curPage = window.location.pathname + window.location.search;
	formField.value = curPage
}

/* EOF */
