var opusContent;
var articleID = "";
var sSection = "";
jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery(document).pngFix(); 
	jQuery('DIV.loadingalign').css({display:"none"});
	jQuery("#background-image").load(function(){
		resizeBackground();
		getNewHome();
		getNewsHome();
	});
	setTimeout("checkImageLoad()",500);
});
jQuery(window).resize(function(){
	resizeBackground();
});

function checkImageLoad()
{
	var eBGImg = document.getElementById("background-image");
	bgWidth = eBGImg.naturalWidth || eBGImg.width;
	if(bgWidth > 0)
	{
		resizeBackground();
		getNewHome();
		getNewsHome();	}
	else
	{
		setTimeout("checkImageLoad()",500);
	}
}


var slideshow=new TINY.slideshow("slideshow");

function resizeBackground()
{
	var sImgWidth, sImgHeight;
	
	var sNavHeight = 100;
	var sFooterHeight = 100;
	var sSpacer = 5;
	var eBGImg = document.getElementById("background-image");
	var eBGFadeImg = $("background-fade");



	var sRatioImageWidth = eBGImg.naturalWidth || eBGImg.width;
	var sRatioImageHeight = eBGImg.naturalHeight || eBGImg.height;
	var sImageAspectRatio = sRatioImageWidth / sRatioImageHeight;
	var sWidth = jQuery(window).width();
	var sHeight = jQuery(window).height();
	var sAspectRatio = sWidth / sHeight
	
//	eBGFadeImg.fx = eBGFadeImg.effect("opacity", {duration: 1600, transition: Fx.Transitions.linear});
//	eBGFadeImg.fx.start(0);
	
	if(sAspectRatio >= sImageAspectRatio)
	{
		sImgWidth = sWidth;
		sImgHeight = Math.ceil(sWidth / sImageAspectRatio);
	}
	else
	{
		sImgWidth = Math.ceil(sHeight * sImageAspectRatio);
		sImgHeight = sHeight;
	}
	
	if(sWidth > 1000)
	{
		sLeft = Math.ceil((sWidth - 1000)/2);
	}
	else
	{
		sLeft = 0;
	}
	
	var sNavGap = sNavHeight + sSpacer;
	var allHeight = sHeight - sNavGap;
	
	sContentHeight = sHeight - sNavHeight - sFooterHeight - (sSpacer * 2);
	if(sContentHeight < 1)
	{
		sContentHeight = 0;
	}
	sFooterPositionHeight = sHeight - 100;
	
	newHomeOffset = allHeight - 230;
	newsHomeOffset = allHeight - 220;

	jQuery('DIV.bgCon').css({visibility:"visible", display:"block", height: sHeight, width: sWidth});
	jQuery('DIV.bgFade').css({left: sLeft, top: sNavGap, height: allHeight});
	jQuery('DIV.nav').css({left: sLeft});
	jQuery('DIV.all').css({left: sLeft, top: sNavGap, height: allHeight});
	jQuery('DIV.scroll').css({height: allHeight});
	jQuery('DIV.cbody').css({height: allHeight});
	jQuery('IMG.bgImg').css({height: sImgHeight, width: sImgWidth});
	jQuery('DIV.homenew').css({top: newHomeOffset});
	jQuery('DIV.homenews').css({top: newsHomeOffset});
	jQuery('DIV.loading').css({display:"none"});
}


window.addEvent("domready", function() {
		opusContent = new iCarousel("opusBody", {  
      idPrevious: "opus_previous",  
      idNext: "opus_next",  
      idToggle: "undefined",  
      item: {  
          klass: "bodyLi",  
          size: 1000  
      },  
      animation: {  
          type: "scroll",  
          duration: 1000,  
          amount: 1  
      }
    });

  	$("navHome").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(0)});  
    $("navStudio").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(1)});
    $("navServices").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(2)});
    $("navWork").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(3)});
    $("navPortfolio").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(4)});
    $("navNews").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(5)});
    $("navContact").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(6)});
    $("navClients").addEvent("click", function(event){new Event(event).stop();removeScoll();opusContent.goTo(7)});
});

function removeScoll()
{
	jQuery('DIV.scrolldiv').css({overflow: "hidden"});
}


function getSection(iSectionID)
{
	jQuery('DIV.livefeed').css({visibility: "visible"});
	jQuery('DIV.livepayload').css({display: "block"});
	jQuery('DIV.payload').css({width: 650});
	document.getElementById("sectPayload").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/section.asp",
  data: "SectionID=" + iSectionID,
  cache: false,
  success: function(html){
		document.getElementById("sectPayload").innerHTML = html;
		jQuery(window).ready(function(){
			jQuery.each(jQuery('img.sectImage'), function() {
				jQuery(this).load(function(){
					jQuery(this).attr("style","visibility:visible;");
				});
			});
		});		
  }
});

}


function portBack()
{
	switch(sSection) {			
		case 1:
		case 2:
		case 3:
			getSection(sSection);
			break;
		default:
			getSection(3);
			break;
	}
}

function getNew()
{
	document.getElementById("livepayload").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/new.asp",
  data: "a=" + 1,
  cache: false,
  success: function(html){
		document.getElementById("livepayload").innerHTML = html;

		jQuery(window).ready(function(){
			jQuery.each(jQuery('img.newImg'), function() {
				jQuery(this).load(function(){
					jQuery(this).attr("style","visibility:visible;");
				});
			});
		});
  }
});
}

function getNewHome()
{
	document.getElementById("homenew").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/newhome.asp",
  data: "a=" + 1,
  cache: false,
  success: function(html){
		document.getElementById("homenew").innerHTML = html;

		jQuery(window).ready(function(){
			jQuery.each(jQuery('img.newImg'), function() {
				jQuery(this).load(function(){
					jQuery(this).attr("style","visibility:visible;");
				});
			});
		});
  }
});
}

function getNewsHome()
{
	document.getElementById("homenew").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/newshome.asp",
  data: "a=" + 1,
  cache: false,
  success: function(html){
		document.getElementById("homenews").innerHTML = html;
  }
});
}

function sectionLoad(iPage)
{
	jQuery('DIV.scrolldiv').css({overflow: "auto"});
	switch(iPage) {			
			case 2:			
			case 6:
				//do nothing
				break;
			case 0:
				getNewHome();
				getNewsHome();
			case 1:
				$("studioMoto").addEvent("click", function(event){new Event(event).stop();showSection("studiomotosect")});
				$("studioFounders").addEvent("click", function(event){new Event(event).stop();showSection("studiofounderssect")});
				$("studioTeam").addEvent("click", function(event){new Event(event).stop();showSection("studioteamsect")});
				showSection("studiomotosect");
				break;
			case 4:
				sSection = "";
				getSection(3);
				$("sectStyle").addEvent("click", function(event){new Event(event).stop();getSection(2)});  
				$("sectProject").addEvent("click", function(event){new Event(event).stop();getSection(1)});  
				$("sectCategory").addEvent("click", function(event){new Event(event).stop();getSection(3)});
				getNew();
				break;
			case 5:
				showArticle();
				/*
				$("newsl1").addEvent("click", function(event){new Event(event).stop();showArticle("news1")});
				$("newsl2").addEvent("click", function(event){new Event(event).stop();showArticle("news2")});
				$("newsl3").addEvent("click", function(event){new Event(event).stop();showArticle("news3")});
				$("newsl4").addEvent("click", function(event){new Event(event).stop();showArticle("news4")});
				$("newsl5").addEvent("click", function(event){new Event(event).stop();showArticle("news5")});
				$("newsl6").addEvent("click", function(event){new Event(event).stop();showArticle("news6")});
				$("newsl7").addEvent("click", function(event){new Event(event).stop();showArticle("news7")});
				$("newsl8").addEvent("click", function(event){new Event(event).stop();showArticle("news8")});
				$("newsl9").addEvent("click", function(event){new Event(event).stop();showArticle("news9")});
				*/
				break;
	}	
}

function getGallery(sId, ssId)
{
	jQuery('DIV.livefeed').css({visibility: "hidden"});
	jQuery('DIV.livepayload').css({display: "none"});
	jQuery('DIV.payload').css({width: 940});
	sSection = sId;
	document.getElementById("sectPayload").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/gallery.asp",
  data: "SectionID=" + sId + "&SubSectionID=" + ssId,
  cache: false,
  success: function(html){
  	//alert(html);
		document.getElementById("sectPayload").innerHTML = html;
		ss$('slideshow').style.display='none';
		ss$('wrapper').style.display='block';
		slideshow.auto=false;
		slideshow.speed=5;
		slideshow.link="linkhover";
//		slideshow.info="information";
		slideshow.thumbs="slider";
		slideshow.left="slideleft";
		slideshow.right="slideright";
		slideshow.scrollSpeed=111;
		slideshow.spacing=5;
		slideshow.active="#fff";
		slideshow.init("slideshow","ssimage","imgprev","imgnext","imglink");
  }
});
}

function getNewGallery(ImageID)
{
	jQuery('DIV.livefeed').css({visibility: "hidden"});
	jQuery('DIV.livepayload').css({display: "none"});
	jQuery('DIV.payload').css({width: 940});
	sSection = "";
	document.getElementById("sectPayload").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/gallery.asp",
  data: "ImageID=" + ImageID,
  cache: false,
  success: function(html){
  	//alert(html);
		document.getElementById("sectPayload").innerHTML = html;
		ss$('slideshow').style.display='none';
		ss$('wrapper').style.display='block';
		slideshow.auto=false;
		slideshow.speed=5;
		slideshow.link="linkhover";
//		slideshow.info="information";
		slideshow.thumbs="slider";
		slideshow.left="slideleft";
		slideshow.right="slideright";
		slideshow.scrollSpeed=111;
		slideshow.spacing=5;
		slideshow.active="#fff";
		slideshow.init("slideshow","ssimage","imgprev","imgnext","imglink");
  }
});
}

function getNewGalleryHome(ImageID)
{
	removeScoll();
	opusContent.goTo(4);
	jQuery('DIV.livefeed').css({visibility: "hidden"});
	jQuery('DIV.livepayload').css({display: "none"});
	jQuery('DIV.payload').css({width: 940});
	document.getElementById("sectPayload").innerHTML = '<img class="throbber" src="/Koshime/images/throbber.gif"/>';
	jQuery.ajax({
  url: "/Koshime/gallery.asp",
  data: "ImageID=" + ImageID,
  cache: false,
  success: function(html){
  	//alert(html);
		document.getElementById("sectPayload").innerHTML = html;
		ss$('slideshow').style.display='none';
		ss$('wrapper').style.display='block';
		slideshow.auto=false;
		slideshow.speed=5;
		slideshow.link="linkhover";
//		slideshow.info="information";
		slideshow.thumbs="slider";
		slideshow.left="slideleft";
		slideshow.right="slideright";
		slideshow.scrollSpeed=111;
		slideshow.spacing=5;
		slideshow.active="#fff";
		slideshow.init("slideshow","ssimage","imgprev","imgnext","imglink");
  }
});
}

function getNewsArticle(iArticle)
{
	removeScoll();
	articleID = iArticle;
	opusContent.goTo(5);
}


var showSection = function(divID){
	jQuery('DIV.studiosection').css({display: "none"});
	var div = $(divID).setStyles({
		display:'block',
		opacity: 0
	});
	new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
};

function getArticle(iArticleID)
{
	articleID = iArticleID;
	showArticle();
}

var showArticle = function(){
	if(typeof(articleID) == "number")
	{
		jQuery('DIV.newsarticle').css({display: "none"});
		jQuery.ajax({
		  url: "/Koshime/getnews.asp",
		  data: "NewsID=" + articleID,
		  cache: false,
		  success: function(html){
				document.getElementById("newsArticle").innerHTML = html;
				var div = $("newsArticle").setStyles({
					display:'block',
					opacity: 0
				});
				new Fx.Style(div, 'opacity', {duration: 1000} ).start(1);
				articleID = "";
		  }
		});
	}
};

