$(document).ready(function(){
    clearImage();
    setupImages();
}).load(function(){
    loadImage();
}).resize(function(){
    loadImage();
});

var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
    var i=xUA.indexOf('opera');
    if(i!=-1){
        var v=parseInt(xUA.charAt(i+6));
        xOp7Up=v>=7;
        xOp6Dn=v<7;
    }
}
else 
    if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){
        xIE4Up=parseFloat(navigator.appVersion)>=4;
        xIE4=xUA.indexOf('msie 4')!=-1;
        xIE5=xUA.indexOf('msie 5')!=-1;
    }
    else 
        if(document.layers){
            xNN4=true;
        }

xMac=xUA.indexOf('mac')!=-1;

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xClientHeight()
{
  var h=0;
  if(xOp6Dn) h=window.innerHeight;
  else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientHeight)
    h=document.documentElement.clientHeight;
  else if(document.body && document.body.clientHeight)
    h=document.body.clientHeight;
  else if(xDef(window.innerWidth,window.innerHeight,document.width)) {
    h=window.innerHeight;
    if(document.width>window.innerWidth) h-=16;
  }
  return h;
}

function xClientWidth()
{
  /*var w=0;
  if(xOp6Dn) w=window.innerWidth;
  else if(document.compatMode == 'CSS1Compat' && !window.opera && document.documentElement && document.documentElement.clientWidth)
    w=document.documentElement.clientWidth;
  else if(document.body && document.body.clientWidth)
    w=document.body.clientWidth;
  else if(xDef(window.innerWidth,window.innerHeight,document.height)) {
    w=window.innerWidth;
    if(document.height>window.innerHeight) w-=16;
  }*/
  var w=1100;
  return w;
}

function clearImage(){
    if ($('#content-image').get(0))
        $('#content-image').get(0).innerHTML = "";
}

function loadImage(){
    $('#right-column #preloader').show();
    $('#content-image').get(0).style.backgroundImage = '';
//    $('#content-image').hide();

    var h = Math.floor(xClientHeight()*0.75);
    var w = Math.floor(xClientWidth()-350);
    
    $('#content-image').get(0).style.width = w+'px';
    $('#content-text').get(0).style.width = w+'px';
    $('#content-text').get(0).style.overflowX = 'hidden';

    var i = new Image();
    i.onload = function() {
        $('#right-column #preloader').hide();
//        $('#content-image').show();
    $('#content-image').get(0).style.backgroundPosition = 'top left';
    $('#content-image').get(0).style.backgroundImage = 'url(/i/'+images[(currentImage-1)]+')';
	//$('#content-image').get(0).style.backgroundImage = 'url(/resize.php?h='+h+'&w='+w+'&s=i/'+images[(currentImage-1)]+')';
//    $('#content-image').get(0).innerHTML = '<a href="#" onclick="zoomImage(); return false;"><img src="/assets/images/plusnew.gif" class="zoom2" /></a>';
    }
    i.src = '/i/'+images[(currentImage-1)];
	//i.src = '/resize.php?h='+h+'&w='+w+'&s=i/'+images[(currentImage-1)];

}

function zoomImage(){
    var z = $('#zoom').get(0);
    var h = xClientHeight();
    var w = xClientWidth();
    z.style.display = 'block';
    $('#zoom-bg').get(0).style.display = 'block';
    z.style.backgroundPosition = 'bottom left';
    z.style.backgroundImage = 'url(/resize.php?h='+h+'&w='+w+'&s=i/'+images[(currentImage-1)]+')';
    z.innerHTML = '<a href="#" onclick="unzoomImage(); return false;"><img src="/assets/images/minus.gif" class="zoom" /></a>';
}

function unzoomImage(){
    var z = $('#zoom').get(0);
    z.style.display = 'none';
    $('#zoom-bg').get(0).style.display = 'none';
    z.innerHTML = '';
}

function deactiveateImages() {
    $('ul.image-list a').each(function(i) {
        if (this.id) { 
            if (this.id.substring(5) != currentImage) { 
                $('a#'+this.id).removeClass('active');
            }
            else {
                $('a#'+this.id).addClass('active');
            }
            return false;
        }
    });
}

function setupImages() {
    $('ul.image-list a').each(function(i) {
        if (this.id) { 
            $('a#'+this.id).click(function(){
                this.blur();
                currentImage = this.id.substring(5);
                deactiveateImages();
                loadImage();
                return false;
            })
        }
    });
}

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
  if(window.screen)if(isCenter)if(isCenter=="true"){
    var myLeft = (screen.width-myWidth)/2;
    var myTop = (screen.height-myHeight)/2;
    features+=(features!='')?',':'';
    features+=',left='+myLeft+',top='+myTop;
  }
  window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function playVideo(x) {
    OpenBrWindow('/movie/view/'+x,'movie','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no','360','280','true');
}
