var viewportwidth;
var viewportheight;
 
window.innerWidth = window.innerWidth
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
if (typeof window.innerWidth == 'undefined')
{
 	var oBody = (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) ? 
     document.documentElement : 
     document.getElementsByTagName('body')[0];
     
 	window.innerWidth = oBody.clientWidth ;
 	window.innerHeight = oBody.clientHeight ;
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}


function addToBookmarks(title, url){
	if(!url)
	{
		var url = document.location.href;
		if (document.all) url = url.replace(/\\/g,"/");
		url = url.substr(0,url.lastIndexOf("/")+1);
	}

	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

var PositionX = 20;
var PositionY = 20;
var defaultWidth  = 600;
var defaultHeight = 400;
var AutoClose = true;
var _DEBUG;
function popImage(imageURL,imageTitle){
	var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
	if( !imgWin ) { return true; } //popup blockers should not cause errors
	imgWin.document.write('<html><head><title>'+imageTitle+'<\/title>'+
		'<meta http-equiv="imagetoolbar" content="no"/>' +
		'<script type="text\/javascript">\n'+
		'function resizeWinTo() {\n'+
		'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
		'var oH = document.images[0].height, oW = document.images[0].width;\n'+
		'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
		'window.doneAlready = true;\n'+ //for Safari and Opera
		'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
		'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
		'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
		'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
		'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
		'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
		'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
		'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
		'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
		'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
		'}\n'+
		'<\/script>'+
		'<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
		(document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
		'<img src='+imageURL+' alt="Loading image ..." title="" onload="resizeWinTo();">'+
		(document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
	imgWin.document.close();
	if( imgWin.focus ) { imgWin.focus(); }
	return false;
}

function restrictLength(oObject, iMaxLength)
{
	if(oObject.value)
	{
		oObject.value = oObject.value.substring(0, iMaxLength);
	}
}

function toggleMenu(oImg)
{
	var aClasses = oImg.parentNode.className.split(/\s+/);
	var iCollapsePos = (aClasses.length > 0 ? aClasses.indexOf('collapse') : -1 );
	var iExpandPos = (aClasses.length > 0 ? aClasses.indexOf('expand') : -1 );
	
	if(iCollapsePos >= 0)
	{
		aClasses.splice(iCollapsePos, 1);
		aClasses[aClasses.length] = 'expand';
	}
	else
	{
		if(iExpandPos>=0) aClasses.splice(iExpandPos, 1);
		aClasses[aClasses.length] = 'collapse';
	}
 	oImg.parentNode.className = aClasses.join(' ');
}

function popMyImage(img){
	if(img.imagepath)
		popImage( img.imagepath , img.title);
}

function viewPhoto(sImageUrl, sImageTitle, sImagePopup){
	if($('img#mainphoto')) {
		$('img#mainphoto')[0].imagepath= sImagePopup;
		$('img#mainphoto')[0].src = sImageUrl;
		$('img#mainphoto')[0].title = sImageTitle;
		$('img#mainphoto')[0].alt = sImageTitle;
	}
}

$(document).ready(function(){
    jQuery('#carousel').jcarousel(
		{scroll: 5, visible: 6}
	);
    jQuery('#collections').jcarousel(
		{scroll: 1 /*, visible: 2*/}
	);

	/* PNG Fix for IE */

	$.ifixpng('style/images/clear.gif');
	$('.boxButtons').ifixpng();
	$('.fixpng').ifixpng();
	$('.contactBox').ifixpng();
	$('.jcarousel-prev').ifixpng();
	$('.jcarousel-next').ifixpng();
	$('div.txtBox').ifixpng();
});

