var J = jQuery.noConflict();
var slideshowTimer = null;
J(document).ready(function(){
    
    resizeConteiner();
    
    J(window).resize(function(){
		resizeConteiner();
	});        
    
    J('img.img').rotate({angle:-3});
    
    setTimeout('doSlideshow("rotator", true, 5000);', 500);
	
});

function resizeConteiner(){
    var width = J(window).width();
    var w_bg = J('.rotator .bg').width();
    var w_page = parseInt(J('.conteiner').css('min-width'));
    
    if (w_bg > width && w_page < width ) {
        var left =  parseInt( (w_bg - width) / 2 );
        J('.rotator').css('left', '-'+ left + 'px');
    }
    J('.conteiner').width( width );
    
}

function isVisible(obj) { return (obj.css('display') == 'block'); } 

function doSlideshow(objid, start, time){
	if(!J('#' + objid) || !isVisible(J('#' + objid))){
		if(slideshowTimer != null){
			clearTimeout(slideshowTimer);
			slideshowTimer = null;
		}
		return;
	}
	
	if(start){
		clearTimeout(slideshowTimer);
		slideshowTimer = null;
	}
	
	var currObj = J('#' + objid + ' li.current');
	var nextObj = currObj.next();
	if(J('#' + objid + ' li:last').hasClass('current')){ 
		nextObj = J('#' + objid + ' li:first');
	}

	nextObj.addClass('current');
	nextObj.css('opacity', 0).css('z-index','2');
	currObj.removeClass('current').css('z-index','1');
	currObj.animate({opacity:0}, 2000);
	nextObj.animate({opacity:1}, 2000);
	
	slideshowTimer = setTimeout('doSlideshow("' + objid + '", false, ' + time + ');', time);
}

if(J.browser.msie) {
  document.createStyleSheet().addRule('v\\:image', "behavior: url (#default#VML);display:inline-block"); 
  document.namespaces.add('v', 'urn:schemas-microsoft-com:vml'); 
  if(document.documentMode && document.documentMode>=8) { 
	document.writeln('<?import namespace="v" implementation="#default#VML" ?>'); 
  }
}
