 /*
-------------------------------------------------
Global Javascript KnowledgeCenter.co.uk
Author: Hudson Maul
Version: 1.0
--------------------------------------------------
*/

$(document).ready(function(){

prepareNewWindow();
prepareInputs();
prepareTabList();
prepareExpandList();
prepareSelectAll();
prepareForms();
loadSplash();
checkContactForm();

// ie6 only -----------------
if($(".ie6").html()){
	ieSimulateHover();
	ieMenuZindexFix();
}
// end ie6 only -----------------

});

function ieMenuZindexFix() {
	  $(".list-links").find("a").css("position", "static");
	  $("#paper").hover(
			function() {
				$(".list-links").find("a").css("position", "relative");
      },
      	function () {
        	$(".list-links").find("a").css("position", "static");
       });
};


function checkContactForm() {
	if($('.MailFeedBack').html()){  
		window.location = '/contact/thank-you';
		}
}


function downloadRequestForm(){
	
if($('div.errmsg').html()){
	$("#downloadForm").children(".content").css('marginLeft','-510px');
}

$('input[@type=text]', '#downloadRequestForm').change(function(){
var text = $(this).val();
var linked_element = "#"+$(this).attr('class').substring(0, $(this).attr('class').indexOf(" "));
$(linked_element).val(text);
});

$('textarea', '#downloadRequestForm').change(function(){
var text = $(this).val();
var linked_element = "#"+$(this).attr('class').substring(0, $(this).attr('class').indexOf(" "));
$(linked_element).val(text);
});

$('input[@type=checkbox]','#downloadSelectList').change(function(){
var linked_element = "#"+$(this).attr('class');
var name = ","+$(this).attr('title');

if(this.checked){
			$(linked_element).append(name);
}
else {
   	    var t = $(linked_element).val();
   	    $(linked_element).empty();
   	    $(linked_element).append(t.replace(name, ''));
 }
});
}

function prepareForms(){

$('input.required').blur(function(){
	t = $(this).val();
	   // check for empty fields
	   if(t == ''){ 
	   		if(!$(this).siblings('.validation').html()) {
				$(this).after('<span class="validation">'+$(this).attr('title')+' is required</span>');
	   		}
	   }
	   else {
		   $(this).next().remove();
	   }
	
});

}

function prepareDownloadForm() {

if($("#AutoFormPlus7_PanelThanks").html()){
		$("#sItems").hide();
	    $("#dItems").show();

}

var next = $("#downloadForm").find(".next");
var back = $("#downloadForm").find(".back");
var slider = $("#downloadForm").children(".content");

if($('#notification').html()) {
	$(slider).css('left','-500px');
}

// check to see if there are any downloads available
if(!$(".file-table").html()) {
	$("#btnRequestDownloads").after("<p>There are currently no downloads available at this time please visit again soon.</p>");
	$("#btnRequestDownloads").remove();
}
$(next).click(function(event){
            // stop default behaviour
          event.preventDefault();
          // remove click border
          this.blur();
               
	$(slider).animate({marginLeft: -510},"fast", function(){$(slider).children().hide});
});

$(back).click(function(event){
            // stop default behaviour
          event.preventDefault();
          // remove click border
          this.blur();
               
	$(slider).animate({marginLeft: 1},"fast", function(){$(slider).children().hide});
});

};
 
function ieSimulateHover() {
// add class "over" to elements to simulate hover for just ie's sake
	$("ul#nav/li").mouseover(function(){$(this).addClass("over");});
	$("ul#nav/li").mouseout(function(){$(this).removeClass("over")});

 }
 
function prepareNewWindow(){
// set all anchors with class "pop" to open a new window
$("a.pop").click(function(){
   			window.open($(this).attr("href"));
   return false;
   });
 }

function prepareSelectAll(){
$(".select-all").toggle(function(event){
            // stop default behaviour
          event.preventDefault();
          // remove click border
          this.blur();
          
          $("input").attr("checked","checked");
          $(this).empty();
          $(this).append("Deselect")
          
}, function (){
		
		$("input").attr("checked","");
		 $(this).empty();
		$(this).append("Select All")
});
}

function prepareInputs(){

$("input[@type=text]").focus(function(){
	$(this).addClass("focus");
});
$("input[@type=text]").blur(function(){
	$(this).removeClass("focus");
});
$("textarea").focus(function(){
	$(this).addClass("focus");
});
$("textarea").blur(function(){
	$(this).removeClass("focus");
});
}

function prepareTabList(){

$("div.tabList/ul/li").hover(function(){
  $(this).addClass("hover");
   if($(this).attr("class") == "selected") {
     // do nothing
   }
   else {
    $(this).parent().find("li.selected").removeClass("selected")
	$(this).addClass("selected");
   }
   return false;
 },function(){
   $(this).removeClass("hover");
 });

$("div.tabList/ul/li/a").click(function(event){
            // stop default behaviour
          event.preventDefault();
          // remove click border
          this.blur();
});

$("div.tabListVert/ul/li").hover(function(){
  $(this).addClass("hover");
   if($(this).attr("class") == "selected") {
     // do nothing
   }
   else {
    $(this).parent().find("li.selected").removeClass("selected")
	$(this).addClass("selected");
   }
   return false;
 },function(){
   $(this).removeClass("hover");
 });

$("div.tabListVert/ul/li/a").click(function(event){
            // stop default behaviour
          event.preventDefault();
          // remove click border
          this.blur();
});


}

function prepareExpandList(){


$("ul.expand-list/li/h5").toggle(function(){
  	
  	$(this).siblings("div").hide("fast");
  	$(this).parent().removeClass("expanded");
	
   }, function(){
   
   $(this).siblings("div").show("fast");
   $(this).parent().addClass("expanded");
  
});


}

 function loadSplash(){
 
 // store values in variable
 var photo_1 = $("div#splashContent/img").attr("src");
 var word_1 = $("#splash_word1").attr("value");
 var word_2 = $("#splash_word2").attr("value");
 var word_3 = $("#splash_word3").attr("value");
 var word_4 = $("#splash_word4").attr("value");
 var word_5 = $("#splash_word5").attr("value");
 var word_6 = $("#splash_word6").attr("value");
 
 // check page type
if($("body").attr("class") == "homepage") {
  var FO = { xi:"true", ximovie:"/resource/ufo.swf", movie:"/resource/splash_home_new.swf", width:"784", height:"235", majorversion:"8", build:"0" , wmode:"transparent", flashvars:"word1="+word_1+"&word2="+word_2+"&word3="+word_3+"&word4="+word_4+"&word5="+word_5+"&word6="+word_6+"&photo="+photo_1 };
  UFO.create(FO, "splashContent");
}

else if($("body").attr("class") == "indexpage" || $("body").attr("class") == "contentpage" || $("body").attr("id") == "news" || $("body").attr("id") == "products" || $("body").attr("class") == "productpage" || $("body").attr("class") == "umbracoBlogPost" || $("body").attr("class") == "blog")  {
  var FO = { xi:"true", ximovie:"/resource/ufo.swf", movie:"/resource/splash_contentpage_new.swf", width:"784", height:"176", majorversion:"8", build:"0" , wmode:"transparent", flashvars:"word1="+word_1+"&word2="+word_2+"&word3="+word_3+"&word4="+word_4+"&word5="+word_5+"&word6="+word_6+"&photo="+photo_1 };
  UFO.create(FO, "splashContent"); 
}
else {
  // do nothing
}
 

};
 
 



