var lastMC = "";
var readyMCFlag = new Array ();

function thisMovie(movieName) {
	if (window.document[movieName]) 
	{
	  return window.document[movieName];
	}
	
	if (navigator.appName.indexOf("Microsoft Internet")==-1)
	{
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	}
	else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	{
		return document.getElementById(movieName);
	}
}

function playmovie(movieName) {
	//alert(thisMovie(movieName));
	var obj = thisMovie(movieName);
	if (readyMCFlag[movieName]==true || typeof  obj.playMc !="undefined") {
		//alert('playMc');
		obj.playMc();
	} else {
		//alert('playMc 2');
		setTimeout( "playmovie('"+movieName+"')",100);
	}
}

function stopmovie(movieName) {
	var obj = thisMovie(movieName);
	if (readyMCFlag[movieName]==true ||  typeof obj.stopMc  !="undefined") {
		//alert('stopMc');
		obj.stopMc();
	} else {
		//alert('stopMc 2');
		setTimeout( "stopmovie('"+movieName+"')",100);
	}
	
}

function onAfterCyCle () {	
	playmovie (this.id+"-swf");
	//setTimeout("playmovie('"+this.id+"-swf')",50);	
	lastMC = this.id;
	
}

function onBeforeCyCle () {
	if (lastMC !="") {
		stopmovie (lastMC+"-swf");	
	}
}

function readyMc (name) {
	switch(name)
	{
		case "1": readyMCFlag["milk-story-list-on-swf"] = true; break;
		case "2": readyMCFlag["milk-story-list-tw-swf"] = true; break;
		case "3": readyMCFlag["milk-story-list-th-swf"] = true; break;
		case "4": readyMCFlag["milk-story-list-fo-swf"] = true; break;
		case "5": readyMCFlag["milk-story-list-fi-swf"] = true; break;
		case "6": readyMCFlag["milk-story-list-si-swf"] = true; break;
		case "7": readyMCFlag["milk-story-list-se-swf"] = true; break;
	}
}

$(document).ready(function() {
	if ($('#milk-story').get( 0 )) {	
    	// this initialises the demo scollpanes on the page.
    	$('.scroll-bar').jScrollPane();
	}

	// 	Cufon 
		Cufon.set('selector', jQuery);
	    Cufon.replace('.replace-font, #news-fade h2, .footer, #article h2, #aside h2, #article-full h2, #article table th, #features ul li a, .pagenation a, .pagenation-number a, #language li a, #language li span, .header h1, .header span', {hover: true});

	  $('#greeting').hover(function(){
	  		$(this).children('.hover').stop(true, true).animate({opacity: "show", filter: "alpha(opacity=1)"}, "fast");
	  		}, function() {
	  		$(this).children('.hover').animate({opacity: "hide", filter: "alpha(opacity=0)"}, "fast");
	  });
	  
	  $('.greeting-link').hover(function(){
	  		$(this).children('.hover').stop(true, true).animate({opacity: "show", filter: "alpha(opacity=1)"}, "fast");
	  		}, function() {
	  		$(this).children('.hover').animate({opacity: "hide", filter: "alpha(opacity=0)"}, "fast");
	  });

	 if ($('#milk-story').get( 0 )) { 
      $('#milk-story').cycle({
        fx: 'scrollHorz',
        speed: 3000,
        timeout: 27000,
        pager:  '#milk-story-nav',
        pause:   1,
        before:   onBeforeCyCle ,
        after:   onAfterCyCle ,
        pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#milk-story-nav a:eq(' + idx + ')';
        }
      });  
	}

	var dockOptions =
		    { align: 'bottom' // horizontal menu, with expansion UP/DOWN from the middle
		    , labels: 'tr' 
		    , source: function(i){ // replace small JPGs with larger PNGs (that have inverse colouring)...
		        //return $(this).attr('src').replace(/\.png$/, '-hover.png');
				return $(this).attr('longdesc');
		      }
		    };
	$('#product-portfolio').jqDock(dockOptions);

	if ($('#news-topic').get( 0 )) {
	  $('#news-topic ul#news-fade').cycle({
		fx: 'scrollHorz',
		speed:  500,
		timeout: 0,
		prev:   '#news-topic p.prev',
		next:   '#news-topic p.next'
	  });
	}

	if ($('#attract').get( 0 )) {
		var t = $('#attract');	
		$('#attract').jqm({
			trigger: 'a.trigger',
			closeClass: 'close a',
			ajax: '@href',
			target: t,
			modal: true,
			onHide: function(h) { 
				h.o.remove();
				h.w.fadeOut(50);
			},
			overlay: 60});
	}

	if ($('.rounded-img10, .rounded-img30').get( 0 )) {
		$('.rounded-img10, .rounded-img30').prepend('<span></span><span></span><span></span><span></span>');
	}

	/*if ($('[id="content-channel"]').get( 0 )) {
		var txt = $('.header h1').text();
		$('.header').append('<span>'+txt+'</span>');
	}*/
	
	if ($('.banner-conent').get( 0 )) {
		$('.banner-conent p.close').click(function() {
			$('#overlay-banner').hide();
		});
	}

	if ($('#article .pagenation').get( 0 )) {
		$('#article .pagenation a').hover(function(){
			var ttl = $(this).attr('title');
			$('#article .pagenation').append('<span>'+ttl+'</span>');
			$('#article .pagenation').children('span').stop(true, true).animate({opacity: "show", filter: "alpha(opacity=1)"}, "slow");
		}, function() {
			$('#article .pagenation>span').remove();
		});
	}

	$('#sign-in #user, #sign-in #pass, #update-profile #name, #update-profile #address, #update-profile #email').click(function(){
	  $(this).val('');
	});
	$('#sign-in #user').blur(function(){
	  $(this).val('User Name');
	});
	$('#sign-in #pass').blur(function(){
	  $(this).val('Password');
	});

});



















