/*
 * Companysite JS
 * http://www.augmentum.com/
 *
 * Copyright (c) 2009 Augmentum, Inc.
 *
 * Date: 2009-10-30
 * Version: 0.0
 */

//cu3er swf code
var flashvars = {};
flashvars.xml = "config.xml";
var attributes = {};
attributes.wmode = "transparent";
attributes.id = "slider";
swfobject.embedSWF("cu3er.swf", "cu3er-container", "300", "150", "9", "expressInstall.swf", flashvars, attributes);



// JQuery document ready functions
$(document).ready(function(){
	//IE6 warning popup
	$.blockIE6();
	
	//footer slide
    $('.kwicks').kwicks({
      min : 45,
      sticky : true, 
      spacing : 1,
      duration: 500,
      event : 'click'
    });
    
  //accordion content
    $('.accordion-content').accordion({
      header: "h2.content-accordion",
      autoHeight: false,
      alwaysOpen: false
    });
    
   
    
  //slide contact
	$(".toggle-button").toggle(function(){
			if($("#slide-contact").hasClass('closed')){
				$("#slide-contact").animate({left:0}, 500, function(){
					$(this).removeClass('closed').addClass('opened');
					$("a#toggle-link").removeClass('toggle-button').addClass('toggle-button-close');
				});
			}//if close
	},function(){
      $("#slide-contact").animate({left:-510}, 500, function(){
        $(this).removeClass('opened').addClass('closed');
        $("a#toggle-link").removeClass('toggle-button-close').addClass('toggle-button');
      });
	});//toggleBtn click close
	
	//Scolls the images in the testimonials pages.
    $(".scrolling-img").Scroll({line:1, speed:500,timer:0, left: "scrolling-left-button",right:"scrolling-right-button"});
	
	// set the the images FADE when it is hovered.
	$(".scrolling-img").each(function() {
		$(this).find("img.attachment-post-thumbnail.wp-post-image").hover(function() {
			$(this).fadeTo("slow", 0.33);
		}, function() {
			$(this).fadeTo("normal", 1);
		});
	});
/*        
	//Awards popup
    $(".award-popup").each(function(){            
  	    $(this).click(function(){
	        	  //If the popup exists, then just do nothing.
	        	  if($("#award-popup-content").length > 0) return;
	    	      var postTitle = $(this).attr("id");
	    	      $(this).parent().parent().css("position", "relative");
	    	      tagName = this.tagName;
	    	      $(this).parent().parent().append('<div title="awards" id="award-popup-content"></div>');
				  
		    	      // Retrieves data via Ajax.
		    	      $.get("http://172.19.2.105/augmentum-cn/ajax-award-popup.php", {post_title:postTitle}, function(data){
			    	        $("#award-popup-content").html(data);
			    	        var topOffset = $("#award-popup-content").height() - 120;
			    	        topOffset = "-" + topOffset + "px";
			    	        if (tagName == "SPAN") {
			                    topOffset = $("#award-popup-content").height() + 10;
			                    topOffset = "-" + topOffset + "px";
			                    $("#award-popup-content").css("left", "0px");
			                }
			    	        $("#award-popup-content").css("top", topOffset);
			    	        //Binds the click event to the close image
			    	        $('#award-popup-close').click(function() {
			    	        	$("#award-popup-content").remove();
			    	        });
		    	      });
  	    });
  	  });
    
  //add the click of the links in the awards-div
	$(".awards-cover.awards-boxcaption").each(function(){     
	    $(this).click(function(){
		    $(this).parent().children(".award-popup").click();
  		});
	});
	
	//set the z-index of the table in awards
	  $("table.awards-table").hover(
			  function () {
			     $(this).css("z-index","5");
			  },
			  function () {
				  $(this).css("z-index","1");
			  }
	  );
*/	
	  	//new style of the  case studies 
		$('.boxgrid.caption').hover(function(){
			$(".cover.boxcaption", this).css("background","#2A6EBB");
		}, function() {
			$(".cover.boxcaption", this).css("background","#000000");
		});	
	  
	  	// new style of the success-stories 
		$('.success-stories-boxgrid.success-stories-caption').hover(function() {
			$(".success-stories-cover", this).css("background","#2A6EBB");
		}, function() {
			$(".success-stories-cover", this).css("background","#000000");
		});
	  		
		// new style of the awards 
		$('.awards-boxgrid.awards-caption').hover(function() {
			$(".awards-cover", this).css("background","#2A6EBB");
		}, function() {
			$(".awards-cover", this).css("background","#000000");
		});
		

		//empty the tiltes of the images in casestudies
		$("img.animate-image").removeAttr("title");

	  

	  $(".toggle-button").click(function(){
		  if($("div#slide-contact").attr("class")=="closed"){
			  //$("div#whole-slide-form input.wpcf7-validates-as-required").text('');
			  $("div#whole-slide-form").fadeIn("2000");
			  $("div#slide-form-success-msg").fadeOut("2000");
			  $("div#slide-form-success-msg").css("display","none");
			  $("dic#slide-contact span.wpcf7-not-valid-tip").css("display","none");
		  }
	  });
	  
    //remove the validation infos when click the other slides
    $("#kwick_1").click(function(){
      $("div#footer span.wpcf7-not-valid-tip").remove();
      $("div.wpcf7-response-output").css("display","none");
    });
    $("#kwick_2").click(function(){
     $("div#footer span.wpcf7-not-valid-tip").remove();
    $("div.wpcf7-response-output").css("display","none");
    });
    $("#kwick_4").click(function(){
     $("div#footer span.wpcf7-not-valid-tip").remove();
    $("div.wpcf7-response-output").css("display","none");
    });
    
     //handle recruitment query
    if ($("iframe#aug").size() > 0) {
      waitAndRetryQuery();
    }

});
var queryTimeout = null;

function handleJobQuery() {
  var title = getJobTitle();
  var contentDocument = '';
  
  if ('' !== title) {
    var augDocument = getIFrameDocument(document, 'aug');
    
    if (augDocument) {
      contentDocument = getIFrameDocument(augDocument, 'main_content');
      
      if (contentDocument) {
        searchTitle(contentDocument, title);
      } else {
        waitAndRetryQuery();
      }
    } else {
      waitAndRetryQuery();
    }
  }
}

function waitAndRetryQuery() {
  queryTimeout = setTimeout(handleJobQuery, 1000);
}

function getJobTitle() {
  var search = location.search;
  var title = '';
  
  if (search) {
    var equalIndex = search.indexOf('=');
    if (-1 !== equalIndex) {
      title = search.substring(equalIndex + 1);
    }
  }
  
  return title;
}

function getIFrameDocument(currentDocument, aID) {
    var rv = null;
    var element = currentDocument.getElementById(aID);
    if (element) {
      if (element.contentWindow){
        // if contentDocument exists, W3C compliant (Mozilla)
        rv = element.contentWindow.document;
      } else {
        // IE
        rv = currentDocument.frames[aID].document;
      }
    }
    
    return rv;
}

function searchTitle(currentDocument, title) {
  window.console && console.log && console.log("title = " + decodeURI(title));
  var search = currentDocument.getElementById("search_input_key");
  var submitButton = currentDocument.getElementById("position_search_button");
  
  if (search && submitButton) {
    search.value = decodeURI(title);
    submitButton.click();
    if (queryTimeout) {
      clearTimeout(queryTimeout);
    }
  } else {
    waitAndRetryQuery();
  }
}


