/*
----------------------------------------------
 Utimaco Custom JS
 Developed by Ollie Bettany / OrangeMango
 Created: 31/10/2011
----------------------------------------------
*/

var $j = jQuery.noConflict();

$j(document).ready(function() {
  
// SEARCH LABEL REPLACE

  $j(function() {
    $j('.overlabel').addClass('activelabel');
    input = $j('.activelabel').next();

  	$j(input).bind({
  		focus: function () {
  			$j(this).prev().fadeOut(60);
  		},
  		blur: function () {
  			if (!this.value) {
  				$j(this).prev().fadeIn(60);
  			}
  		}
  	});
  });
  
// CALCULATE POSITION OF BACKGROUND IMAGE

  $j(function() {
    ie_extra = 0;
    
    if ($j("body").hasClass('home')) {
      var p = $j("#content .bottom");
      var h = $j("#content .bottom h1");
    } else {
      var p = $j("#content");
      var h = $j("#content h1");
      
      if ($j.browser.msie) {
        ie_extra = 1;
      }
    }

    var imageHeight = ie_extra + 733;
     
    var position = p.position();
    var height = h.height() + 20;
  
    var position_top = height + (Math.round(position.top) - imageHeight); 
  
    if ($j("body").hasClass('clientarea')) {
      position_top = position_top - 1;
    }
    if ($j("body").hasClass('product-detail')) {
      position_top = position_top - 8;
    }
  
    var bg_position = '0px ' + position_top.toString() + 'px';

    $j("body").css('background-position', bg_position);
  });

// SET HEIGHT OF TAB CONTENT BLOCK IN PARTNER LOCATOR PAGE

  $j(function() {
    var max_height = 0;
    var title_height = $j('.locator .parent h1').height() + 25;
    var instruction_height = $j('.locator .instruction').height() + 31;

  	$j('.locator .child').each(function(index) {

  	  var height = $j(this).height();
      //alert(height);
  	  if (height > max_height) {
        max_height = height;
      }
    });
    $j('.locator .child').css('position', 'absolute');
    $j('.locator .parent').css('height', max_height + title_height + instruction_height);
    $j('.locator .child').css('height', max_height + title_height + instruction_height);
  });
  

// REPLACE HOMEPAGE POLL RADIO BUTTONS WITH IMAGES

  $j(function() {
    $j('.poll input:radio').each(function() {
      $j(this).hide();
      $j('<a class="radio-fx" href="#"><div class="radio-off"></div></a>').insertAfter(this);
    });
    $j('.radio-fx').live('click',function(e) {
      e.preventDefault();
        var $check = $(this).prev('input');
        $j('.radio-fx div').attr('class','radio-off');
        $j(this).find('div').attr('class','radio-on');          
        $check.attr('checked', true);
    });
  });
  
  
// PRODUCTS SPECS DRILLDOWN TOGGLE ON PRODUCT DETAIL PAGE

  $j('ul.showhide li').click(function() {
    $j(this).children('ul').slideToggle('fast');
  });
  
  $j('.gallery a').click(function () {
      $('.gallery > img').hide().filter(this.hash).fadeIn('slow');
      
      $j('.gallery a').removeClass('current');
      $j(this).addClass('current');      
      
      return false;
  }).filter(':first').click();
  
  
// PARTNER LOCATOR MAP AND TABS

  // Set europe as default
	$j("#listitem_3").addClass('current');
	$j("#regions").addClass("regionimage_3");
		
	// Hover over regions
	$j('#m_regions area').hover(function() {
	  $j("#regions").removeClass();
	  $j(".locator .parent").removeClass('current');
    var index = $j(this).attr("id").split("_")[1];
    $j("#listitem_" + index).addClass('current');
    $j("#regions").addClass("regionimage_" + index);
  });
  
  // Hover over tabs
  $j('.locator .parent').hover(function() {
	  $j("#regions").removeClass();
	  $j(".locator .parent").removeClass('current');
    var index = $j(this).attr("id").split("_")[1];
    $j("#listitem_" + index).addClass('current');
    $j("#regions").addClass("regionimage_" + index);
  });
  
  $j(".product-slider .images .outer").click(function() {
    window.location = $j(this).find('a').attr('href');
  });


// FADING TAB CONTENT ON HOMEPAGE (USES JQUERY TOOLS)

	$j(".slidetabs").tabs(".images > div", {

  	// enable "cross-fading" effect
  	effect: 'fade',
  	fadeOutSpeed: "slow",

  	// start from the beginning after the last tab
  	rotate: true

  // use the slideshow plugin. It accepts its own configuration
  }).slideshow({
    autoplay: true,
      clickable: false,
    	interval: 5000
  });
  
// SIMPLE TABS ON PRODUCT DETAIL PAGE (USES JQUERY TOOLS)

  $j(".product-tabs").tabs(".tabcontent > section");
  $j('input[type=submit]').addClass('button');
	$j('.whitepapers .three-cols img').removeAttr('height');
	$j('.whitepapers .three-cols img').removeAttr('width');
  // LIGHTBOX EFFECT
  $j('a.lightbox').lightBox({
	overlayOpacity: 0.6,
    imageLoading: 'fileadmin/templates/images/lightbox-ico-loading.gif',
  	imageBtnClose: 'fileadmin/templates/images/lightbox-btn-close.gif',
  	imageBtnPrev: 'fileadmin/templates/images/lightbox-btn-prev.gif',
  	imageBtnNext: 'fileadmin/templates/images/lightbox-btn-next.gif',
  	containerResizeSpeed: 350,						
	}); // Select all links with lightbox class
  
//Additions: OrangeMango 
  $j('input#mailformWhitepaper').attr('value', document.title);


});
