var mouseInitX = 0
var mouseInitY = 0


// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

$(document).ready(function(){


// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
});
// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
var tempX
var tempY

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  

  if (mouseInitX == 0 && mouseInitY == 0)
    {
      mouseInitX  = tempX;
      mouseInitY  = tempY;  
    }
  else
    {
      if (mouseInitX  != tempX || mouseInitY  != tempY)
      {
        bindMenuEvent();
        document.onmousemove = null;
      }
    }
  return true
}




function confirmDelete(message, formId)
{
  var formEl = document.getElementById(formId);
  var result = confirm(message);
  if (result == true)
  {
    formEl.submit();
  }
  else
  {
    return false;
  }

}

$(document).ready(function(){

$("#PACKfindSearch select").change(function() {

        if (this.value != '')
            this.form.submit();

    });

    $('a.tabPACKfind').click(function() {

        $('#KeywordSearch').hide(1,function(){$('#PACKfindSearch').slideDown('fast')});
        

    })

    $('a.tabSearch').click(function() {
        $('#PACKfindSearch').hide(1,function(){$('#KeywordSearch').slideDown('fast')});
        

    })



$('a.tabSubscribe').click(function(){
  $('#logonBox').slideUp('fast')
  $('#subscribeBox').slideDown('fast')

})

$('a.tabLogon').click(function(){
  $('#subscribeBox').slideUp('fast')
  $('#logonBox').slideDown('fast')

  if ($('#YourPasswordLogon input').val() != '')
    {
     
     $('#YourPasswordLogon').css({'background-image':'URL('+jqueryFilesPath+'/global/images/backgrounds/form_boxes/emptyInput.gif)'})
    }

  if ($('#YourEmailLogon input').val() != '')
    {
     $('#YourEmailLogon').css({'background-image':'URL('+jqueryFilesPath+'/global/images/backgrounds/form_boxes/emptyInput.gif)'})
    }


  
})

$('#registerEmailTop').focus(function(){
  $('#YourEmailSubscribe').css({'background-image':'URL('+jqueryFilesPath+'/global/images/backgrounds/form_boxes/YourEmailSubscribeEmpty.gif)'})

})

$('#YourEmailLogon input').focus(function(){
  $('#YourEmailLogon').css({'background-image':'URL('+jqueryFilesPath+'/global/images/backgrounds/form_boxes/emptyInput.gif)'})

})

$('#YourPasswordLogon input').focus(function(){
  $('#YourPasswordLogon').css({'background-image':'URL('+jqueryFilesPath+'/global/images/backgrounds/form_boxes/emptyInput.gif)'})

})



$('.external').click(function() {
window.open($(this).attr("href"),null);
return false;
})});

function getBasketItemIdsAmounts(idPrefix)
{

	var inputs = document.getElementsByTagName('input');
	var result = '';
	for (i=0; i<inputs.length; i++)
	{
		
		if (inputs[i].type == 'text')
		{

			if (inputs[i].id.substring(0, idPrefix.length) == idPrefix)
			{
				var singleId = inputs[i].id.substring(idPrefix.length);
				

				
				if (result == '')
					result += singleId;
				else
					result += ','+singleId;
					
				var singleA = inputs[i].id.substring(idPrefix.length);
				result += ','+inputs[i].value;
				

			}
		}
	}

	return result;
}

function AddToBasket(id)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('shoppingBasket').innerHTML='Updating...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('shoppingBasket').innerHTML=xmlhttp.responseText;
attentionCall('basketgif')
xmlhttp = false;
}
	}
	xmlhttp.open("GET",addToBasketTarget+"?id="+id+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function RemoveFromBasket(id)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('shoppingBasket').innerHTML='Updating...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('shoppingBasket').innerHTML=xmlhttp.responseText;
xmlhttp = false;
}
	}
	xmlhttp.open("GET",removeFromBasketTarget+"?id="+id+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function DecryptCard(encrypted,num)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

	var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		{
		document.getElementById('cardNumber'+num).innerHTML='....';
		}
	
		if(xmlhttp.readyState==4)
		{
			document.getElementById('cardNumber'+num).innerHTML=xmlhttp.responseText;
			xmlhttp = false;
		}
	}
	xmlhttp.open("GET",decryptionTarget+"?encstring="+encrypted+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function UpdateBasket(idsAmounts)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('shoppingBasket').innerHTML='Updating...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('shoppingBasket').innerHTML=xmlhttp.responseText;
xmlhttp = false;
}
	}
	xmlhttp.open("GET",basketUpdateTarget+"?ids_amounts="+idsAmounts+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}

function UpdateOrder(id, name, value)
{
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var timestamp = new Date().getTime();
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==1)
		document.getElementById('updateOrderDiv').innerHTML='Saving...';
	
		if(xmlhttp.readyState==4)
		{		document.getElementById('updateOrderDiv').innerHTML=xmlhttp.responseText;
xmlhttp = false;
}
	}
	xmlhttp.open("GET",orderUpdateTarget+"?id="+id+"&name="+name+"&value="+value+"&anti-cache=" + timestamp,true);
	xmlhttp.send(null);


}


function attentionCall(id)
{
$('#'+id).fadeOut('slow',function(){
$('#'+id).fadeIn('slow',
function(){
$('#'+id).fadeOut('slow',
function(){
$('#'+id).fadeIn('slow')}
)}
)}
)}



$(document).ready(function(){

  var theCookieValue
  var theURL = document.location.href.replace(jquerySiteURL,'').substring(0,21).toLowerCase()
  if (theURL == '/packaging-suppliers/')
  {
     theCookieValue = $.cookies.get('backlink')
     if (theCookieValue)
	 {
	 $('#rightHeader a').attr('href',theCookieValue)
	 }
  }
  else
  {
    $.cookies.set('backlink',document.location.href)
  }




})

$(document).ready(function() {

$(".premiumAccess").parent().append("<img class=\"premiumStamp\" src=\""+jqueryFilesPath+"/global/images/premium-stamp.png\" alt=\"\" />");

}); 




 $(document).ready(function() {

 $("#Supplier20-80percent #rightContent div select").change(function () {
                    $("select option:selected").each(function () {
                window.location.href = $(this).val();

              });
           })  

      });


 $(document).ready(function() { 
  $('#registerEmailFooter').focus(function(){
    $(this).val('');
    $(this).css({'color':'#000000'})
    })

  $('#registerEmailFooter').blur(function(){
    $(this).css({'color':'#9A9A9A'})
  })

   $('#signInButton').hover(function(){
    $(this).attr('src',jqueryFilesPath+'/global/images/graphics/button-innovationsSignUp2.gif')
   },
   function(){
    $(this).attr('src',jqueryFilesPath+'/global/images/graphics/button-innovationsSignUp.gif')
   }
   )
    
});






$(document).ready(function(){
var sponsorName = $('.leftSponsor').attr('id');

if (sponsorName != null && sponsorName != '')
{
  var so = new SWFObject(jqueryFilesPath+'/global/flash/Sponsors/'+sponsorName+'.swf', 'Sponsorship', '181', '199', '#FFFFFF');
so.addVariable('enablejs', 'true');
so.addParam('allowScriptAccess','sameDomain');
so.addParam('pluginspage','http://www.macromedia.com/go/getflashplayer');
so.addParam('scale', 'showall');
so.addParam('wmode', 'transparent');
so.write(sponsorName); 
}

var thisEdition = $("#title h1 a").text();

$(".leftSponsor").click(function() {
 pageTracker._trackPageview("/banner-stats/"+thisEdition+"/Left/");
 var noFlashLink = $(this).attr('href');
 if (noFlashLink != null && noFlashLink != '')
  window.location = noFlashLink;
/* return false; */
});

$(".topSponsor").click(function() {
 var thisLinkTo = $(this).attr('href');
 if (thisLinkTo.indexOf('advertise') == -1)
       pageTracker._trackPageview("/banner-stats/"+thisEdition+"/Top/"); 

if (!($(this)).hasClass('external'))
 window.location = thisLinkTo;
 return false;
});

});


/*********  Image Slideshow for innovations **************/

$(document).ready(function(){

$("body").append("<div id=\"preloadIMGs\" style=\"visibility:hidden; position:absolute; top:0;\" />");
   $("#imageContainer li img").each(function (i) {
 var thePicLoad = $(this).attr('src');  thePicLoad = thePicLoad.replace("/thumb/","/prev/");
   $("#preloadIMGs").append("<img src=\""+thePicLoad+"\" alt=\"\" title=\"imagePreload-"+i+"\" style=\"visibility:hidden;\" />");
   });

    $("#imageContainer:has('ul')").addClass("gallery");
    $("#imageContainer:has('ul') .mainImage").wrap("<div id=\"previewCont\" />");

    $("#imageContainer ul").replaceWith("<div id=\"thumbsBlock\"><div id=\"thumbStripLeft\" class=\"thumbStripButton\"><img src=\""+jqueryFilesPath+"/Global/Images/graphics/leftArrow.gif\" alt=\"\" /></div><div id=\"thumbStripCont\"><div id=\"thumbStrip\">"+$("#imageContainer ul").html()+"</div></div><div id=\"thumbStripRight\" class=\"thumbStripButton\"><img src=\""+jqueryFilesPath+"/Global/Images/graphics/rightArrow.gif\" alt=\"\" /></div></div>");


 $("#imageContainer li:eq(0) img").css("margin-top","-15px");
 $("#imageContainer li:eq(0) img").css("margin-left","-1px");
 $("#imageContainer li:eq(0) img").css("width","106px");

    var totImg =  (($("#thumbStrip img").length) * 106) + "px";
    $("#thumbStrip").css("width",totImg);

    $("#thumbStripLeft").live('click', function() {
        $("#thumbStripCont").scrollTo("-=318px", 600 );  
     });

    $("#thumbStripRight").live('click', function() {
        $("#thumbStripCont").scrollTo("+=318px", 600 );
     });

    $("#thumbStrip li").live('click', function() {
        var thePic = $(this).find('img').attr('src');
        thePic = thePic.replace("/thumb/","/prev/");


$("#previewCont").css("height", $("#previewCont img").height() + "px");


var imageNo = $(this).prevAll().size();
var theNewHeight = $("#preloadIMGs img:eq("+imageNo+")").height() + "px";



        $("#previewCont img").fadeOut(300, function () {       
         // $(this).remove();

$("#previewCont").animate(                        
                        {height: theNewHeight}
                , 200 ,function(){
                           $("#previewCont").html("<img class=\"mainImage\" style=\"display:none;\" src=\""+thePic+"\" alt=\"\"  />");
          $("#previewCont img").fadeIn(300);
                            }); 
          
        });
        return false;
     });

});


/*** Languages Bubble Tips ***/

$(document).ready(function(){
$("a.language").each(function () {
 $(this).append("<span class=\"langTip\">"+$(this).attr("title")+"</span>");
 $(this).attr("title","");
});
 
$("a.language").hoverIntent(function() {
$(this).children("span").stop(true, true).animate({opacity: "show", top: "20"}, "slow");
}, function() {
$(this).children("span").animate({opacity: "hide", top: "35"}, "fast");
});

});



$(document).ready(function(){



$(".SearchConfigurator_Selectors select option:selected").each(function(){

if ($(this).text() != "-All-") {
  $(this).parent().parent().prev().css("font-weight","bold");
  $(this).parent().css( {'font-weight':'bold', 'color':'#0079CC' } ); 
  $(this).siblings().css({'font-weight':'normal','color':'#000000' }); 
  $(this).css("font-weight","bold"); 
}

});


function makeScrollable($wrapper, $container){
	var extra 			= 50;
	var wrapperHeight 	= $wrapper.height() ;
	$wrapper.css({overflow: 'hidden'});
	$wrapper.scrollTop(0);
	$wrapper.unbind('mousemove').bind('mousemove',function(e){
		var ulHeight 	= $container.outerHeight() + 2*extra ;
		var top 		= (e.pageY - $wrapper.offset().top) * (ulHeight-wrapperHeight ) / wrapperHeight - extra;
		$wrapper.scrollTop(top);
	});

}
			

$('.SearchConfigurator_Links .linkBlock').each(function(){
$(this).find('ul').wrap('<div class="scroller" />')

makeScrollable($(this).find('.scroller'),$(this).find('ul'))

})

$("a[href^='http:']:not([href*='" + window.location.host + "'])").not("[href*=software.webpac.com]").click(
function(){
   theLink = $(this).attr('href').replace('http://','')
   pageTracker._trackPageview("/external-links/"+theLink);
})
});

