var ltie7 = $.browser.msie && $.browser.version < 7;
var videoConfig = {
	videoFile: 'http://s3.video2.blip.tv/0220000034155/KimAronson-TwentySeconds70930.flv',
	autoPlay: false,
  autoBuffering: false,
  initialScale: 'scale',
	loop: false,
	controlBarGloss:'high',
	showMenu: false,
	showFullScreenButton: false,
  //usePlayOverlay: true,
	controlsOverVideo: 'no',
  timeDisplayFontColor: 0xbbbbbb,
  //controlBarBackgroundColor: 0xffffff,
	splashImageFile: '/img/video-splash.jpg'
}
var flashConfig = {
  //expressInstall: '/swf/expressinstall.swf',
  version: [7,0],
  bgcolor: '#000000'
}

jQuery(function($) { 
	var PAGE_NAME = $('body').attr('id');
  $('#mainnav li:not(:last)').append('<img src="img/mainnav-div.png" style="width:1px;height:28px;" />');
  $('#'+PAGE_NAME+'-nav').attr('src', 'img/'+PAGE_NAME+'-nav-on.png').addClass('selected');
  $('img.rollover:not(.selected)').hover(
    function(){
      $(this).attr('src', $(this).attr('src').replace(/\.png/, '-on.png'));
      if (ltie7 && $(this).css('filter')) {
        $(this).css('filter', $(this).css('filter').replace(/\.png/, '-on.png'));
      }
    },
    function(){
      $(this).attr('src', $(this).attr('src').replace(/-on\.png/, '.png'));
      if (ltie7 && $(this).css('filter')) {
        $(this).css('filter', $(this).css('filter').replace(/-on\.png/, '.png'));
      }
    }
  );
  if (ltie7) {
    $.ifixpng('/img/blank.gif');
    $('#index #content, #about-us #content, #press #content').ifixpng();
    $('#mainnav img, img.trans').ifixpng();
    $('#'+PAGE_NAME+'-nav').ifixpng();
  }

	flashConfig.src = '/swf/header.swf';
	flashConfig.width = 1024;
	flashConfig.height = 134;
  $('#header').flashembed(flashConfig);

	flashConfig.width = 256;
	flashConfig.height = 98;
	flashConfig.src = '/swf/promo1.swf';
  $('#promo1').flashembed(flashConfig);
	flashConfig.src = '/swf/promo2.swf';
  $('#promo2').flashembed(flashConfig);
	flashConfig.src = '/swf/promo3.swf';
  $('#promo3').flashembed(flashConfig);
	flashConfig.src = '/swf/promo4.swf';
  $('#promo4').flashembed(flashConfig);
	
  if (/^index|about-us|press$/.test(PAGE_NAME)){
		flashConfig.src = '/swf/FlowPlayerDark.swf';
		flashConfig.width = 472;
		flashConfig.height = 362;
		videoConfig.videoFile = $('#media-src').attr('href');
	  $('#media').flashembed(flashConfig, { config: videoConfig });
	}
	else if (/^gallery$/.test(PAGE_NAME)){
		if (getQueryParam('media') == 'videos') {
			flashConfig.src = '/swf/FlowPlayerDark.swf';
			flashConfig.width = '100%';
			flashConfig.height = '100%';
			videoConfig.videoFile = $('#video-selector a:eq(0)').attr('href');
		  var videoPlayer = flashembed('video-player', flashConfig, {config: videoConfig});  
			$('#video-selector a').click(function(){
				videoConfig.autoPlay = true;
				videoConfig.videoFile = $(this).attr('href');
				videoPlayer.setConfig(videoConfig);  
				return false;
			});
	  } else {
			flashConfig.src = '/swf/viewer.swf';
			flashConfig.width = '100%';
			flashConfig.height = '100%';
			flashembed('picture-player', flashConfig);  
	  }
	}
	else if (/^products$/.test(PAGE_NAME)){
		$('#thumb-images a').click(function(){
			$('#detail-image').attr('src', this.href);
			return false;
		});
	}
	else if (/^investor-relations$/.test(PAGE_NAME)){
		$('#subject').val('Investor Relations Form Submission');
		$('#good-url').val('/investor-relations.php?response=good');
		$('#bad-url').val('/investor-relations.php?response=bad');
	}
});

function getQueryParam(key){
	var pairs = window.location.search.substring(1).split(/[&]/);
  for (var i=0, j=pairs.length; i<j; i++) {
    var n = pairs[i].split("=");
		if (key == unescape(n[0].replace(/^\s+|\s+$/g,''))){
			return unescape(n[1].replace(/\+/g, ' '));
		} else {
			return false;
		}
  }
}
