/************************************************

* White paper registration and contact message *

************************************************/



var registrationEmailLabel;

var contactNameLabel;

var contactEmailLabel;

var contactMessageLabel;



$(document).ready(function(){

  /*jQuery('#jcarousel').jcarousel({scroll: 1});*/

  

  $("#text2").hide();

  

  $("#textButton1").click(function() {

    $("#text1").fadeOut("slow", function(){

      $("#text1").hide();

      $("#text2").fadeIn("slow");

    });

    return false;

  });

  

  $("#home").click(function() {

    $("#text2").fadeOut("slow", function(){

      $("#text2").hide();

      $("#text1").fadeIn("slow");

    });

    return false;

  });

  ///////////////who we are///////////

   $("#the-team-text").hide();

    $("#who-we-are").css('color', '#e01b21');

    $("#our-approch-text").hide();

  

  $("#the-team").click(function() {

    $("#who-we-are-text").fadeOut("slow", function(){

      $("#who-we-are-text").hide();

	   $("#our-approch-text").hide();

	  $("#the-team").css('color', '#e01b21');

	  $("#who-we-are").css('color', '#EEEEEE');

	  $("#our-approch").css('color', '#EEEEEE');

      $("#the-team-text").fadeIn("slow");

    });

    return false;

  });

  

  $("#who-we-are").click(function() {

    $("#our-approch-text").fadeOut("slow", function(){

      $("#our-approch-text").hide();

	  $("#the-team-text").hide();

	   $("#the-team").css('color', '#EEEEEE');

	  $("#who-we-are").css('color', '#e01b21');

	  $("#our-approch").css('color', '#EEEEEE');

      $("#who-we-are-text").fadeIn("slow");

    });

    return false;

  });

  

  $("#our-approch").click(function() {

    $("#the-team-text").fadeOut("slow", function(){

      $("#who-we-are-text").hide();

	  $("#the-team-text").hide();

	  $("#the-team").css('color', '#EEEEEE');

	  $("#who-we-are").css('color', '#EEEEEE');

	  $("#our-approch").css('color', '#e01b21');

      $("#our-approch-text").fadeIn("slow");

    });

    return false;

  });

  $("#publications-text").hide();

  $("#digital-text").hide();

  $("#instore-text").hide();

  $("#photography-text").hide();

  $("#packaging-text").hide();

  //$("#what-we-do-text").hide();

  $("#publications").click(function() {

    $("#what-we-do-text").fadeOut("slow", function(){

      $("#what-we-do-text").hide();

	  $("#digital-text").hide();

 	  $("#instore-text").hide();

 	  $("#photography-text").hide();

  	  $("#packaging-text").hide();

	  $("#digital").css('color', '#EEEEEE');

	  $("#instore").css('color', '#EEEEEE');

	  $("#photography").css('color', '#EEEEEE');

	  $("#packaging").css('color', '#EEEEEE');

	  $("#publications").css('color', '#e01b21');

      $("#publications-text").fadeIn("slow");

    });

    return false;

  });

   $("#digital").click(function() {

    $("#publications-text").fadeOut("slow", function(){

      $("#what-we-do-text").hide();

	  $("#publications-text").hide();

 	  $("#instore-text").hide();

 	  $("#photography-text").hide();

  	  $("#packaging-text").hide();

	  $("#publications").css('color', '#EEEEEE');

	  $("#instore").css('color', '#EEEEEE');

	  $("#photography").css('color', '#EEEEEE');

	  $("#packaging").css('color', '#EEEEEE');

	  $("#digital").css('color', '#e01b21');

      $("#digital-text").fadeIn("slow");

    });

    return false;

  });

   $("#instore").click(function() {

    $("#digital-text").fadeOut("slow", function(){

      $("#what-we-do-text").hide();

	  $("#publications-text").hide();

 	  $("#digital-text").hide();

 	  $("#photography-text").hide();

  	  $("#packaging-text").hide();

	  $("#publications").css('color', '#EEEEEE');

	  $("#digital").css('color', '#EEEEEE');

	  $("#photography").css('color', '#EEEEEE');

	  $("#packaging").css('color', '#EEEEEE');

	  $("#instore").css('color', '#e01b21');

      $("#instore-text").fadeIn("slow");

    });

    return false;

  });

   $("#photography").click(function() {

    $("#instore-text").fadeOut("slow", function(){

      $("#what-we-do-text").hide();

	  $("#publications-text").hide();

 	  $("#digital-text").hide();

 	  $("#instore-text").hide();

  	  $("#packaging-text").hide();

	  $("#publications").css('color', '#EEEEEE');

	  $("#digital").css('color', '#EEEEEE');

	  $("#instore").css('color', '#EEEEEE');

	  $("#packaging").css('color', '#EEEEEE');

	  $("#photography").css('color', '#e01b21');

      $("#photography-text").fadeIn("slow");

    });

    return false;

  });

   $("#packaging").click(function() {

    $("#photography-text").fadeOut("slow", function(){

      $("#what-we-do-text").hide();

	  $("#publications-text").hide();

 	  $("#digital-text").hide();

 	  $("#instore-text").hide();

  	  $("#photography-text").hide();

	  $("#publications").css('color', '#EEEEEE');

	  $("#digital").css('color', '#EEEEEE');

	  $("#instore").css('color', '#EEEEEE');

	  $("#photography").css('color', '#EEEEEE');

	  $("#packaging").css('color', '#e01b21');

      $("#packaging-text").fadeIn("slow");

    });

    return false;

  });

  /////////////////////////

  

  registrationEmailLabel = $("#registrationEmail").val();

  contactNameLabel = $("#contactName").val();

  contactEmailLabel = $("#contactEmail").val();

  contactMessageLabel = $("#contactMessage").val();

  

  $("#registrationSubmit").click(register);

  $("#contactSubmit").click(contact);

});



function register() {

  $("#registrationSubmit").attr('disabled', true);

  var email = $.trim($("#registrationEmail").val());

  if (email == registrationEmailLabel) email = '';

  $("#registrationResponse").html("Sending...");

  $.post("php/process.php", {email: email, action: 'register'}, registerResponse);

  return false;

}

  

function registerResponse(aResult) {

  var result = eval( '(' + aResult + ')' ); 

  $("#registrationResponse").html(result.response);

  $("#registrationSubmit").attr('disabled', false);

  if (result.success)

    $("#registrationEmail").val(registrationEmailLabel);

}



function contact() {

  $("#contactSubmit").attr('disabled', true);

  var email = $.trim($("#contactEmail").val());

  var name = $.trim($("#contactName").val());

  var message = $.trim($("#contactMessage").val());

  if (email == contactEmailLabel) email = '';

  if (name == contactNameLabel) name = '';

  if (message == contactMessageLabel) message = '';

  $("#contactResponse").html("Sending...");

  $.post("php/process.php", {email: email, name: name, message: message, action: 'contact'}, contactResponse);

  return false;

}

  

function contactResponse(aResult) {

  var result = eval( '(' + aResult + ')' );

  $("#contactResponse").html(result.response);

  $("#contactSubmit").attr('disabled', false);

  if (result.success) {

    $("#contactName").val(contactNameLabel);

    $("#contactEmail").val(contactEmailLabel);

    $("#contactMessage").val(contactMessageLabel);

  }

}



$().ready(function() {

  $('#dialog').jqm();

});



$(document).ready(function (){

  $("#marquee490").marquee({yScroll: "bottom"});

});





/*******************

* Content resizing *

********************/



function getWindowHeight() {

  var result = 0;

  if (self.innerHeight)

    result = self.innerHeight;

  else if (document.documentElement && document.documentElement.clientHeight)

    result = document.documentElement.clientHeight;

  else if (document.body)

    result = document.body.clientHeight;



  return result;

}



function getWindowWidth() {

  var result = 0;

  if (self.innerWidth)

    result = self.innerWidth;

  else if (document.documentElement && document.documentElement.clientWidth)

    result = document.documentElement.clientWidth;

  else if (document.body)

    result = document.body.clientWidth;



  return result;

}



function updateSize() {

  var page = document.getElementById('page');

  var w = getWindowWidth();

  var h = getWindowHeight();

  page.style.height = Math.max(600, h) + 'px'

  

  if ((window.isIE && w < page.scrollWidth) || (!window.isIE && h < 600))

    page.style.width = (w - window.scrollbarWidth) + 'px'

  else

    page.style.width = w + 'px'

  

  page.style.visibility = 'visible';

  

  var modal = document.getElementById('jqmWindow');

  if (modal != null)

    modal.style.top = (document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px';

}



function loadComplete() {

  window.isIE = navigator.appName == 'Microsoft Internet Explorer';

  

  var i = document.createElement('p');

  i.style.width = '100%';

  

  i.style.height = '200px';

  

  var o = document.createElement('div');

  o.style.position = 'absolute';

  o.style.top = '0px';

  o.style.left = '0px';

  o.style.visibility = 'hidden';

  o.style.width = '200px';

  o.style.height = '150px';

  o.style.overflow = 'hidden';

  o.appendChild(i);

  

  document.body.appendChild(o);

  var w1 = i.offsetWidth;

  var h1 = i.offsetHeight;

  o.style.overflow = 'scroll';

  var w2 = i.offsetWidth;

  var h2 = i.offsetHeight;

  if (w1 == w2) w2 = o.clientWidth;

  if (h1 == h2) h2 = o.clientWidth;

  

  document.body.removeChild(o);

  

  window.scrollbarWidth = w1 - w2;

  window.scrollbarHeight = h1 - h2;

  

  updateSize();

}



window.onresize = updateSize;

window.onload = loadComplete;



/*function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {

  // The index() method calculates the index from a

  // given index who is out of the actual item range.

  var idx = carousel.index(i, mycarousel_itemList.length);

  carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));

};



function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt) {

  carousel.remove(i);

};


function mycarousel_getItemHTML(item) {

  return '<a href="include/popup.php?id='+item.id+'"><img src="' + item.url + '" width="230" height="150" alt="' + item.title + '" border="0" /></a>';

};
*/


/*$(function() {

  jQuery('#mycarousel').jcarousel({

    scroll: 1,

    wrap: 'wrap',

    itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},

    itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}

  });

});*/





/***********************************************

* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)

* This notice MUST stay intact for legal use

* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code

***********************************************/



var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)

var loadedobjects=""

var rootdomain="http://"+window.location.hostname

var bustcacheparameter=""



function ajaxpage(url, containerid) {

  var page_request = false;

  if (window.XMLHttpRequest) // if Mozilla, Safari etc

    page_request = new XMLHttpRequest();

  else if (window.ActiveXObject) { // if IE

    try {

      page_request = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e) {

      try {

        page_request = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e){}

    }

  } else

    return false;

  

  page_request.onreadystatechange = function() {

    loadpage(page_request, containerid)

  }

  

  if (bustcachevar) //if bust caching of external page

    bustcacheparameter = (url.indexOf("?") != -1) ? "&"+new Date().getTime() : "?" + new Date().getTime();

  

  page_request.open('GET', url+bustcacheparameter, true);

  page_request.send(null);

}



function loadpage(page_request, containerid) {

  if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))

    document.getElementById(containerid).innerHTML=page_request.responseText

}



function loadobjs(){

  if (!document.getElementById)

    return;

  

  for (var i = 0; i < arguments.length; i++) {

    var file = arguments[i];

    var fileref = "";

    if (loadedobjects.indexOf(file) == -1) { //Check to see if this object has not already been added to page before proceeding

      if (file.indexOf(".js") != -1) { //If object is a js file

        fileref = document.createElement('script')

        fileref.setAttribute("type", "text/javascript");

        fileref.setAttribute("src", file);

      } else if (file.indexOf(".css") != -1){ //If object is a css file

        fileref = document.createElement("link")

        fileref.setAttribute("rel", "stylesheet");

        fileref.setAttribute("type", "text/css");

        fileref.setAttribute("href", file);

      }

    }

    

    if (fileref != "") {

      document.getElementsByTagName("head").item(0).appendChild(fileref);

      loadedobjects += file + " "; //Remember this object as being already added to page

    }

  }

}
