/* Main Javascript file for Abraxas Photography */

// $e function for gettting element id's (to cut down typing), would normally just use $ but using prototype libary on gallery page and don't want conflicts
function $e(id) 
{
	return document.getElementById(id); 
}

// We show the image by setting the visibility of the element and incrementing the height smoothly
// Used mainly for the main image slide down on each page
var hh = 0; // 0 value height
var inter; // Initiate inter variable

function ShowImg(height, id)
{
	// Stop the loop as desired height reached
	if (hh == height)
	{
		// Show the flash text when height reached
		d = $e('flashText');
		d.style.display = 'block';
		
		clearInterval(inter);
		return;
	}
	
	var object = $e(id);
	object.style.visibility = 'visible';
	hh += 3;
	object.style.height = hh + 'px';
}

var hh2 = 0; // 0 value height
var inter2; // Initiate inter variable

function ShowBkg(height, id)
{
	// Stop the loop as desired height reached
	if (hh2 == height)
	{
		
		clearInterval(inter2);
		return;
	}
	
	var object = $e(id);
	object.style.visibility = 'visible';
	hh2 += 3;
	object.style.height = hh2 + 'px';
}

// Set a function to control opacity of an element
function opacity(id, opacStart, opacEnd, millisec) 
{
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if (opacStart > opacEnd) {
		for (i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if (opacStart < opacEnd) {
		for (i = opacStart; i <= opacEnd; i++) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//Change the opacity for different browsers
function changeOpac (opacity, id) 
{
	var object = $e(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

// Function for switching images on mouseover event
function SimpleSwap(el,which) 
{
  el.src=el.getAttribute(which || "origsrc");
}

// Initial image swap page setup called from body.onload
function SimpleSwapSetup() 
{
  var x = document.getElementsByTagName("img");
  for (var i = 0; i < x.length; i++)
  {
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image -
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src = oversrc;

    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,\'oversrc\');");
    x[i].onmouseout = new Function("SimpleSwap(this);");

    // save original src
    x[i].setAttribute("origsrc", x[i].src);
  }
}

// Open new centered window
function openwin(theURL, Name, popW, popH, scroll, resizable, tool, menu) 
{
var winleft = (screen.width - popW) / 2;
var winUp = (screen.height - popH) / 2;
var winProp = 'width='+popW+',height='+popH+',left='+winleft+',top='+winUp+',scrollbars='+scroll+',resizable='+resizable+',toolbar='+tool+',menubar='+menu+''
var Win = window.open(theURL, Name, winProp)
if (parseInt(navigator.appVersion) >= 4) { Win.window.focus(); }
}

// Preload other page images, has a wait of 5 seconds when body loads so not to intefere with page animations
function preload() 
{
  
  var images = new Array();
  images[0] = "2nd_photographer_page.jpg";
  images[1] = "booking_page.jpg";
  images[2] = "contact_page.jpg";
  images[3] = "ctestimonials_page.jpg";
  images[4] = "experience_page.jpg";
  images[5] = "feedback_page.jpg";
  images[6] = "first_visit_page.jpg";
  images[7] = "gallery_page.jpg";
  images[8] = "kam_page.jpg";
  images[9] = "links_page.jpg";
  images[10] = "newsletter_page.jpg";
  images[11] = "online_page.jpg";
  images[12] = "packages_page.jpg";
  images[13] = "parents_page.jpg";
  images[14] = "press_page.jpg";
  images[15] = "privacy_page.jpg";
  images[16] = "production_page.jpg";
  images[17] = "products_page.jpg";
  images[18] = "recent_wedding_page.jpg";
  images[19] = "shows_page.jpg";
  images[20] = "terms_page.jpg";
  images[21] = "vouchers_page.jpg";
  images[22] = "opening_page.jpg";
  
  for (var i = 0; i < images.length; i++) 
  {
	var source = 'http://www.abraxasphoto.co.uk/images/page_images/' + images[i];
      
    // preload image
    var new_img = new Image();
    new_img.src = source;
  }
  
}

// Preload first 10 gallery images whenever you get a chance
function gPreload() 
{
  
  var gImages = new Array();
  gImages[0] = "1.jpg";
  gImages[1] = "2.jpg";
  gImages[2] = "3.jpg";
  gImages[3] = "4.jpg";
  gImages[4] = "5.jpg";
  gImages[5] = "6.jpg";
  gImages[6] = "7.jpg";
  gImages[7] = "8.jpg";
  gImages[8] = "9.jpg";
  gImages[9] = "10.jpg";
  
  for (var i = 0; i < gImages.length; i++) 
  {
	var gsource = 'http://www.abraxasphoto.co.uk/images/galleries/full/' + gImages[i];
      
    // preload image
    var new_gimg = new Image();
    new_gimg.src = gsource;
  }
  
}

// Preload other page images, has a wait of 2.5 seconds when gallery body loads so not to intefere with page animations
function galleryPreload() 
{
  
  //  Gallery Images
  var cImages = new Array();
  cImages[0] = "1.jpg";
  cImages[1] = "2.jpg";
  cImages[2] = "3.jpg";
  cImages[3] = "4.jpg";
  cImages[4] = "5.jpg";
  cImages[5] = "6.jpg";
  cImages[6] = "7.jpg";
  cImages[7] = "8.jpg";
  cImages[8] = "9.jpg";
  cImages[9] = "10.jpg";
  cImages[10] = "11.jpg";
  cImages[11] = "12.jpg";
  cImages[12] = "13.jpg";
  cImages[13] = "14.jpg";
  cImages[14] = "15.jpg";
  cImages[15] = "16.jpg";
  cImages[16] = "17.jpg";
  cImages[17] = "18.jpg";
  cImages[18] = "19.jpg";
  cImages[19] = "20.jpg";
  cImages[20] = "21.jpg";
  cImages[21] = "22.jpg";
  cImages[22] = "23.jpg";
  cImages[23] = "24.jpg";
  cImages[24] = "25.jpg";
  
   // For gallery large popups
  for (var n = 0; n < cImages.length; n++) 
  {
	var csource = 'http://www.abraxasphoto.co.uk/images/galleries/large/' + cImages[n];
      
    // preload image
    var new_cimg = new Image();
    new_cimg.src = csource;
	
  }
  
}

// Used on your feedback form
function otherRadio(type)
{
	var obj = $e('otherSelected');
	if (type == 'show')
	{
		obj.innerHTML = 'If you selected website, venue or other<br /> please give further details here:<br /><input class="form_colour" type="text" id="hear_other" name="hear_other" size="36" maxlength="60" />';
	}
	else
	{
		obj.innerHTML = '';
	}
}

// Function for displaying gallery
function galleryProcess()
{
	opacity('gallery_img', 0, 100, 1000);
	setTimeout('opacity("gallery_img", 100, 8, 2000)', 1500);
	setTimeout('opacity("gallery", 0, 100, 3000)', 3000);
}

// Gallery rollover
function galleryIn(ele)
{
	var theEle = ele;
	theEle.style.border = '1px solid #AA4A00';
}

// Gallery rollout
function galleryOut(ele)
{
	var theEle = ele;
	theEle.style.border = '1px solid #ffffff';
}

// quick rollover
function formIn(ele)
{
	var theEle = $e(ele);
	theEle.style.color = '#AA4A00';
}

// quick rollout
function formOut(ele)
{
	var theEle = $e(ele);
	theEle.style.color = '#ffffff';
}

var hh3 = 22; // 22 value height
var inter3; // Initiate inter variable

function ShowEnquiry(height, id)
{
	// Stop the loop as desired height reached
	if (hh3 == height)
	{
		clearInterval(inter3);
		return;
	}
	
	var object = $e(id);
	hh3 += 3;
	object.style.height = hh3 + 'px';
}

// Used to display ajax loading
function showLoading()
{
	var content = '<div style="width:31px;height:31px;margin-right:auto;margin-left:auto;">';
	content += '<img src="images/loading2.gif" width="31" height="31" alt="Loading" border="0" />';
	content += '</div>';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function showSuccess(transport)
{
	var response = transport.responseText;
	
	var content = response;
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function showFailure(transport)
{
	var content = '<span class="bl">Un-successful</span>';
	content += '<br /><br />';
	content += 'We are sorry but the submission failed.';
	content += '<br /><br />';
	content += '<a href="javascript:history.go(-1);">Please click</a> here to try again.';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Do ajax call for form submission
function doWork(form)
{
	var theURL = 'http://www.abraxasphoto.co.uk/register/process.php';
	var theForm = $e(form);
	var formData = Form.serialize(theForm);
	
	var doWork = new Ajax.Request( theURL, { method: 'post', parameters: formData, onLoading: showLoading, onComplete: showSuccess, onFailure: showFailure} );
}

// For booking form only, needed different layout

// Used to display ajax loading on booking form
function bookLoading()
{
	var content = '<div style="position:relative;top:580px;width:31px;height:31px;margin-right:auto;margin-left:auto;">';
	content += '<img src="images/loading2.gif" width="31" height="31" alt="Loading" border="0" />';
	content += '</div>';
	content += '<div style="position:relative;top:621px;width:150px;height:100px;margin-right:auto;margin-left:auto;text-align:center;">';
	content += 'Please wait while your booking is being processed..';
	content += '<br /><br />';
	content += 'You will shortly be re-directed to a new page where you can pay the deposit amount.';
	content += '</div>';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function bookSuccess(transport)
{
	var response = transport.responseText;
	
	var content = '<div style="position:relative;top:580px;width:700px;height:400px;margin-right:auto;margin-left:auto;">';
	content += response;
	content += '</div>';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Used to display ajax response
function bookFailure(transport)
{
	var content = '<div style="position:relative;top:580px;width:700px;height:400px;margin-right:auto;margin-left:auto;">';
	content += response;
	content += '<span class="bl">Un-successful</span>';
	content += '<br /><br />';
	content += 'We are sorry but the submission failed.';
	content += '<br /><br />';
	content += '<a href="javascript:history.go(-1);">Please click</a> here to try again.';
	content += '</div>';
	
	var ele = $e('formCont');
	ele.innerHTML = content;
}

// Do ajax call for form submission
function bookWork(form)
{
	var theURL = 'http://www.abraxasphoto.co.uk/register/process.php';
	var theForm = $e(form);
	var formData = Form.serialize(theForm);
	
	var doWork = new Ajax.Request( theURL, { method: 'post', parameters: formData, onLoading: bookLoading, onComplete: bookSuccess, onFailure: bookFailure} );
}





// Used to display ajax loading on free report form
function reportLoading()
{
	var content = '<div style="position:relative;top:0px;width:31px;height:31px;margin-right:auto;margin-left:auto;">';
	content += '<img src="images/loading2.gif" width="31" height="31" alt="Loading.." border="0" />';
	content += '</div>';
	content += '<div style="position:relative;top:41px;width:250px;height:70px;margin-right:auto;margin-left:auto;text-align:center;">';
	content += 'Please wait while your download is being prepared..';
	content += '</div>';
	
	var ele = $e('report');
	ele.innerHTML = content;
}

// Used to display ajax response
function reportSuccess(transport)
{
	var response = transport.responseText;
	var ele = $e('report');
	ele.innerHTML = response;
}

// Used to display ajax response
function reportFailure(transport)
{
	var content = '<span class="bl">Un-successful</span>';
	content += '<br /><br />';
	content += 'We are sorry but the submission failed.';
	content += '<br /><br />';
	content += '<a href="javascript:window.location.reload();">Please click</a> here to try again.';
	
	var ele = $e('report');
	ele.innerHTML = content;
}

// Do ajax call for form submission
function reportWork(form)
{
	var theURL = 'http://www.abraxasphoto.co.uk/register/process.php';
	var theForm = $e(form);
	var formData = Form.serialize(theForm);
	
	var doWork = new Ajax.Request( theURL, { method: 'post', parameters: formData, onLoading: reportLoading, onComplete: reportSuccess, onFailure: reportFailure} );
}