
$(document).ready(init);

function init() {
	//fixHeaders();
	//startSIFR();
	initScroll();
	initSlideshow();
	fixContactEmail();
	fixCaseSWFs();
	sidebar.init();
	styleImages();

	
}

function fixCaseSWFs() {
	 var swfs = $("a[href$='.swf']");
	 for( i = 0 ; i < swfs.length ; ++i ) {
	 	swfLink = swfs[i].href;
	 	//swfSize = swfs[i].parentNode.getElementsByTagName('a')[0].href;
		swfSize = swfs[i].innerHTML;
	 	swfSize = swfSize.split('-');
	 	swfs[i].parentNode.className = 'imgContainer';
	 	swfs[i].parentNode.id = 'swfContainer-' + i;
	 	swfSO = new SWFObject(swfLink, "swf-" + i, swfSize[0], swfSize[1], "8", "#F8F8F8");
	 	swfSO.write('swfContainer-' + i);	
	 }
}

function styleImages() {
	$('#content a:has(img)').addClass('imgContainer');
	$('#content a:has(img)').append('<span class="zoom">+</span>');
}

var sidebar = {
	numOfArts : 0,
	current : 0,
	timer : false,

	init : function() {
		if( document.getElementById('content').offsetHeight < document.getElementById('right').offsetHeight ) {
				if(jQuery.browser.msie) {
					document.getElementById('content').style.height = ( document.getElementById('right').offsetHeight + 20 ) + 'px';				
				} else {
					document.getElementById('content').style.height = ( document.getElementById('right').offsetHeight  ) + 'px';				
				}

		}
		sidebar.numOfArts = $('#right .article').length;
		$('#right .article:odd').addClass('odd');
		$('#right .article:even').addClass('even');		
		$('#right .article:gt(1)').hide();		
		
		setInterval(sidebar.animate, 7000);
	},
	
	animate : function() {
		oldCurrent = sidebar.current;
		newCurrent = sidebar.current + 2;
		if( newCurrent > sidebar.numOfArts ) { newCurrent = 0; }
		$('#right .article:eq(' + oldCurrent + ')').fadeOut(1000);
		$('#right .article:eq(' + (oldCurrent + 1) + ')').fadeOut(1000);
		$('#right .article:eq(' + newCurrent + ')').fadeIn(1000);
		$('#right .article:eq(' + (newCurrent + 1) + ')').fadeIn(1000);
		sidebar.current = newCurrent;
	}
}

function fixContactEmail() {
	var email = $('#contact_mail').text();
			email = email.split('at');
			email = email[0] + '@' + email[1];
			email = email.split('dot');
			email = email[0] + '.' + email[1];
			$('#contact_mail').text(email);
			$('#contact_mail').attr('href', 'mailto:' + email);			
}

function initSlideshow() {
	if( $('#slideshow').is('div') ) {
		var so = new SWFObject("/swf/Slideshow.swf", "slide", "960", "370", "9", "#000000");
		so.write("slideshow");	
	} else if( $('#top_image').is('.hasSwf') ) {
		var imgName = $('#top_image img').attr('src');
				imgName = imgName.split('.jpg');
				imgName = imgName[0];
		var so = new SWFObject(imgName + ".swf", "slide", "960", "370", "9", "#000000");
		so.write("top_image");			
	}
}

function initScroll() {
		$('#cases ul').width( ( $('#cases a').length * 180 - 30 ) + 'px');
		$("#cases ul li:last").css({'margin-right' : '0'});
		$('#cases .content').width( ( ( $('#cases .article').length * 385 ) - 25 ) + 'px');
		$("#cases .article:last").css({'margin-right' : '0'});		
		$(function(){
			$('.scroll-pane').jScrollHorizontalPane({scrollbarHeight:20, showArrows:true, dragMinWidth:120, dragMaxWidth:120, arrowSize:20, resize:false});
		});
}

function fixHeaders() {
	var H2s = $('h2');
	for( i = 0 ; i < H2s.length; ++i ) {
		temp = H2s[i].childNodes[0].nodeValue;
		H2s[i].removeChild(H2s[i].childNodes[0]);
		H2s[i].appendChild(document.createTextNode(temp.toLowerCase()));
	}
	var H2s = $('h3');
	for( i = 0 ; i < H2s.length; ++i ) {
		temp = H2s[i].childNodes[0].nodeValue;
		H2s[i].removeChild(H2s[i].childNodes[0]);
		H2s[i].appendChild(document.createTextNode(temp.toLowerCase()));
	}	
}

function startSIFR() {
	if(typeof sIFR == "function") {
    //sIFR.setup();
    //sIFR.replaceElement('h2', '../orator.swf','#006600');
    //sIFR.replaceElement(named({sSelector:"body #content h2", sFlashSrc:"/swf/orator.swf", sColor:"#006600", sLinkColor:"#cc6600", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
	
    sIFR.replaceElement(named({sSelector:"body #footer h2", sFlashSrc:"/swf/orator.swf", sColor:"#006600", sLinkColor:"#cc6600", sBgColor:"#000000", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));	
	
    sIFR.replaceElement(named({sSelector:"body h3", sFlashSrc:"/swf/orator.swf", sColor:"#006600", sLinkColor:"#cc6600", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=0"}));
	};	
}