// (c) Alex Bokov 2008-2011

function setCookie (name, value, days, path, domain, secure) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";

      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=/" : "") +		// ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=mossinepartners.com" : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}

function preload_images() {
	var	d = document; 
	if ( d.images )
	{ 
		if ( !d.p ) d.p=new Array();
		var i, j=d.p.length, a=preload_images.arguments; 	
		for ( i=0; i<a.length; i++ ) if ( a[i].indexOf("#") != 0 ) 
		{ 
			d.p[j]=new Image; d.p[j++].src=a[i]; 
			d.p[j]=new Image; d.p[j++].src=a[i].replace('-large.jpg','-xl.jpg'); 
		}
	}
}

// ---- (c) not Alex Bokov ;-)
// Cross-browser BlendTrans Filter JavaScript, Fade in/out
// http://brainerror.net/scripts/javascript/blendtrans/
// blendtrans.js
// slightly modified by Alex Bokov - for this site only

function getNaturalHeight(img) {
        if( img.naturalHeight ) {
            return img.naturalHeight;
        } else {
            lgi = new Image();
            lgi.src = img.src;
            return lgi.height;
        }
}

function showObj( obj )
{
    if ( ! obj.style ) obj.visibility = "visible"; else obj.style.visibility = "visible";
}

function hideObj( obj )
{
    if ( ! obj.style ) obj.visibility = "hidden"; else obj.style.visibility = "hidden";
}

function moveObjTo( obj, x, y )
{
    if ( ! obj.style ) { obj.top = y; obj.left = x; } else { obj.style.top = y + "px"; obj.style.left = x + "px"; }
}

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.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; }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

var	bi_timeout	= new Array();
function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if ( document.getElementById(imageid).src.substr(document.getElementById(imageid).src.length-imagefile.length, imagefile.length ) != imagefile )	/* don't replace if same already */ 
	{
		//set the current image as background
		document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
		//make image transparent
		changeOpac(0, imageid);
	
		//make new image
		document.getElementById(imageid).src = imagefile;

		//fade in image
		for(i = 0; i <= 100; i++) {
			clearTimeout( bi_timeout[i] );
			bi_timeout[i] = setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
			timer++;
		}
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}


