var products = ['design','web','studio','organizer'];
var curProduct = products[Math.floor(Math.random()*4)];;
var playAnimation;
var fadeAnimation;
var rotation;
var webSamplePage;
var webSamplePageWidth = 583;

dojo.addOnLoad (function() {
    var controller;
    var nextSlash = location.pathname.indexOf('/', 1);
    if(nextSlash >1) {
        //controller = location.pathname.substr(1, nextSlash-1);
    } else {
        controller = location.pathname.substr(1);
    }
    
    //alert(controller)
    switch(controller) {
        case '':
            dojo.byId('page-'+curProduct).className = '';
            rotation = setTimeout("productRotation()", Math.floor(Math.random()*10000)+10000);     
        case 'web':
            dojo.require("dojo.fx");
            webSamplePage = parseInt(dojo.byId('web-sample-page').value);
            dojo.byId('slide-obj').style.width = (webSamplePage * webSamplePageWidth)+'px';
            break;
        case 'studio':
        	videoPlay('rangkid','thaipbs-rangkidtv');
            break;
        case 'organizer':
        	dojo.byId('project-0').className = 'bold';
        	curObj = dojo.byId('project-0');
        	//showOrganizer(dojo.byId('project-id-0').value, dojo.byId('project-0'));
        	//break;
        default:
    }
    /*
    if(location.pathname=='/' || location.pathname=='/index.php') {
    	dojo.byId('page-'+curProduct).className = '';
        rotation = setTimeout("productRotation()", Math.floor(Math.random()*10000)+10000);
    }
    // check web sample page number
    if(dojo.exists('slide-obj')) {
    	dojo.require("dojo.fx");
        webSamplePage = parseInt(dojo.byId('web-sample-page').value);
        dojo.byId('slide-obj').style.width = (webSamplePage * webSamplePageWidth)+'px';
        //alert(dojo.byId('slide-obj').style.width)
    }
    */

});


function showBodyAfterPopup()
{
	dojo.byId('body').style.display = '';
}

/* Dinsor Popup */
dojo.addOnLoad( function() {
	dojo.xhrPost({
		url: '/popup',
		handleAs: 'text',
		handle: function(content) {
			//alert(content);
			if(content!='') {
				dijit.byId('dinsorPopup').show();
				//dojo.byId('show-popup').innerHTML = content;
				dojo.byId('image').src = '/public/popup/'+content;
				//setTimeout("dijit.byId('dinsorPopup').hide();" ,5000);
				setTimeout("showBodyAfterPopup()" ,5100); 
			} else {
				dojo.byId('body').style.display = '';
			}
		}
	});		
});