function changeNavWidth(theNewWidth) {
	document.forms.navWidthForm.newWidth.value = theNewWidth;
	document.forms.navWidthForm.submit();		
}
function toggleTag(tagName,givenValue){
	var x = document.getElementsByTagName(tagName);
	for (var i = 0; i < x.length; i++){
		x[i].style.visibility = givenValue;
	}
}
	
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function P7_autoLayers() { //v1.2 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 var a = parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;
  for (var u=0;u<10;u++) {p7c[u] = new Array();}}
 for(k=0; k<p7c[a].length; k++) {
  if((g=MM_findObj(p7c[a][k]))!=null) {
   b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=1; k<args.length; k++) {
  if((g=MM_findObj(args[k])) != null) {
   b=(document.layers)?g:g.style;b.visibility="visible";f=false;
   for(j=0;j<p7c[a].length;j++) {
    if(args[k]==p7c[a][j]) {f=true;}}
  if(!f) {p7c[a][p7c[a].length++]=args[k];}}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// quick browser tests
var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;
var obj = "";				

// show/hide the div
/*function doFocus(obj) {
	alert('IN');
	theLinkID = obj.id;
	if (ie4 || ie5) {alert('ie4');if (document.all[theLinkID]) document.all[theLinkID].focus();}
	if (ns6) {alert('ns6');if (document.getElementById[theLinkID]) document.getElementById[theLinkID].focus();}
	if (ns4) {alert('ns4');if (document.getElementById[theLinkID]) document.getElementById[theLinkID].focus();}
}*/

// show/hide the div
function doFocus(ID) {
	theLinkID = ID;
	if (ie4 || ie5) {if (document.all[theLinkID]) {document.all[theLinkID].focus();}}
	if (ns6) {if (document.getElementById[theLinkID]) document.getElementById[theLinkID].focus();}
	if (ns4) {if (document.getElementById[theLinkID]) document.getElementById[theLinkID].focus();}
}

/*Steve 30/04/2008*/
/*

addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
   more code to run on page load 
});


*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addResizeEvent(func) {
  var oldresize= window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      oldresize();
      func();
    }
  }
}

function addClickEvent(func) {
  var oldonclick = window.onclick;
  if (typeof window.onclick != 'function') {
    window.onclick = func;
  } else {
    window.onclick = function() {

      if (oldonclick) {
        olonclick();
      }
      func();
    }
  }
}

/*lightbox popout functionality */

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}

jQuery.fn.fadeToggle = function(speed, easing, callback) { 
   return this.animate({opacity: 'toggle'}, speed, easing, callback); 
}; 

//Show add new lightbox form fields
function setVisible(obj,type) {
	obj = document.getElementById(obj);
	if(type == "visibility"){
		obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	} else {
		obj.style.display = (obj.style.visibility == 'block') ? 'none' : 'block';
	}
}

function toggleLightbox(aID,cID,iconID,ePos){
	if (aID=='selected'){
	anycheck_state('check');
	if (selectedcount !='undefined' && selectedcount>0){
		aID = selectedartworkids;
		}
	else 
		{alert('Please use the checkboxes in the corner of each image\n(or the "select all" button) to select items first.');return false;}
	}
	document.frmLightbox.artwork_ID.value=aID;
	document.frmLightbox.category.value=cID;
	
	var bwzContainer = jQuery('#brandworkzContainer').offset();
	var iconLeft = jQuery('#' + iconID).offset().left + jQuery('#' + iconID).width();
	var iconTop = jQuery('#' + iconID).offset().top + 1;
	if(ePos == null){
		ePos = "right";	
	}
	
	if(ePos == "right"){
		jQuery('#lightboxLayer').css('left',iconLeft - bwzContainer.left)
								.css('top',iconTop - bwzContainer.top)
								.fadeToggle('fast');		
	}else if(ePos == "bottom"){
		jQuery('#lightboxLayer').css('left',jQuery('#' + iconID).offset().left)
								.css('top',(iconTop - bwzContainer.top) + jQuery('#' + iconID).height())
								.fadeToggle('fast');
	}

	return false;
}

function addToAlbumsSimple(aID,cID, iconID){
	if (aID=='selected'){
		anycheck_state('check');
		if (selectedcount !='undefined' && selectedcount>0){
			aID = selectedartworkids;
			//Force lightbox form to submit and refresh page
			jQuery('#frmLightbox').submit();
		}
		else {
			alert('Please use the checkboxes in the corner of each image\n(or the "select all" button) to select items first.');
			return false;
		}
	}
	
	document.frmLightbox.artwork_ID.value=aID;
	document.frmLightbox.category.value=cID;
	
	return false;
}

function toggleLightboxContextualMenu(aID,cID){
/*	if (aID=='selected'){
	anycheck_state('check');
	if (selectedcount !='undefined' && selectedcount>0){
		aID = selectedartworkids;
		}
	else 
		{alert('Please use the checkboxes in the corner of each image\n(or the "select all" button) to select items first.');return false;}
	}
*/	
	document.frmLightbox.artwork_ID.value=aID;
	document.frmLightbox.category.value=cID;
	document.frmLightboxTopMenu.artwork_ID.value=aID;
	document.frmLightboxTopMenu.category.value=cID;
	
	//var bwzContainer = jQuery('#brandworkzContainer').offset();
	//var iconLeft = jQuery('#' + iconID).offset().left + jQuery('#' + iconID).width();
	//var iconTop = jQuery('#' + iconID).offset().top + 1;
	
	//jQuery('#lightboxLayer').css('left',iconLeft - bwzContainer.left)
//							.css('top',iconTop - bwzContainer.top)
//							.fadeToggle('fast');
	
	return false;
}

function closeBox(){
	jQuery(document).trigger('close.facebox');
}

//Function to submit multiple assets to a lightbox. Used in the My Albums dropdown and Actionbar
function submitMultipleToLightbox(lightboxid){
	var checkedArtworkIDs = '';
	
	if(jQuery('.thumbnail_checkbox:checked').length) {
		jQuery('.thumbnail_checkbox:checked').each(function(){
			checkedArtworkIDs += this.value + ',';	
		});
		
		
		jQuery('#frmLightboxVariable #variableArtworkID').val(checkedArtworkIDs);
		jQuery('#frmLightboxVariable #variableLightbox').val(lightboxid);
		
		jQuery('#frmLightboxVariable').submit();
	} else {
		alert('Please use the checkboxes in the corner of each image\n(or the "select all" button) to select items first.');
	}
}

//Function to submit a single asset to a lightbox. Used on the category browse contextual menu
function submitSingleToLightbox(lightboxid, artworkID){
	jQuery('#frmLightboxVariable #variableArtworkID').val(artworkID);
	jQuery('#frmLightboxVariable #variableLightbox').val(lightboxid);	
	jQuery('#frmLightboxVariable').submit();
}


var iePNGLoader =
 {
   loadThis: function(img)
   {
     if (navigator.userAgent.indexOf("MSIE") >-1 && parseInt(navigator.appVersion) <= 6)
     {
		var pSrc = img.src;
		var srcHeight = img.offsetHeight;
		var srcWidth = img.offsetWidth;

		img.onload = null;
		img.src = "/BMS/images/spacer.gif";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + pSrc + "',sizingMethod='scale')";
		img.style.width = srcWidth;
		img.style.height = srcHeight;	

     }
   }
 };
 
function fixImage(obj){
	
	obj.onload= function(){
			iePNGLoader.loadThis(this);
	};
	
}


