var PageSizes = null;
var PageScrolls = null;
var showOverlay = function()
{
	PageSizes = getPageSize();
	$('overlay').style.height = (PageSizes[1] + 'px');	
	$('overlay').show();
	$('SecondContent').style.left = ((PageSizes[0]/2)-250 + 'px');;
	$('SecondContent').update('Se incarca...va rugam asteptati');
	$('SecondContent').show()
	window.location = '#';
}

var hideOverlay = function()
{
	$('SecondContent').hide();
	$('overlay').hide();
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

var Debug = true; //set this to false to not display the js errors
var CM = new function(){}
CM.currentSection = '';
CM.loadModule = function(ModuleName, ListJSONObject)
{
	if (CM.currentSection == ModuleName && !ListJSONObject)
		return;
    CM.currentSection = ModuleName
	$$('#links a').each(function(link) {
       link.className = 'linkInactive';
    })
    if (CM.currentSection == 'Modele')
    	$('butModele').className = 'linkActive';
    /**
     * load the data thru ajax
     * */
    var Message = new Object();
    Message.RequestModule = ModuleName
    Message.JSONAttachedObject = ListJSONObject;
    var A = new Ajax();
	A.post('./index.php', 'Message='+Object.toJSON(Message), function(transport)
    	{
    		try
    		{
	    		switch (CM.currentSection) {
	    			case 'Contact':
	    			//new Effect.Fade('navigationBar')   			
	    			$('MainContainer').innerHTML = transport;
	    			break;
	    			case 'Accesories':
	    			var ObjResponse = transport.evalJSON()
	    			$('MainContainer').update(ObjResponse.ClientAccesories);
	    			//$('navigationBar').update(ObjResponse.NavigationData);
	    			//new Effect.Appear('navigationBar')
	    			AccesoriesList.init($F('JSONListMessage'));
	    			break
	    			default:
	    			var ObjResponse = transport.evalJSON();
	    			$('MainContainer').innerHTML = ObjResponse.ClientModele;
	    			//$('navigationBar').update(ObjResponse.NavigationData);
	    			//new Effect.Appear('navigationBar')
	    			MotoList.init($F('JSONListMessage'));
	   				break;
	    		}
    		}
    		catch(Ex)
    		{
    			alert(Ex.message+' la PAjax')
    		}
    	});
}
CM.AjaxFailure = function(transport)
{
	if (Debug)
		alert('Error on Ajax Request: '+transport.responseText);
	return;
}
Event.onDOMReady(function() {
	$('butModele').onclick = function(){CM.loadModule('Modele');}
	$('butModele1').onclick = function(){CM.loadModule('Modele');}
	$('butContact').onclick = function(){CM.loadModule('Contact');}
	$('butAccesorii').onclick = function(){CM.loadModule('Accesories')}
	$('butAccesorii1').onclick = function(){CM.loadModule('Accesories')}
	
	//get some contact informations
	var Message = new Object;
	Message.RequestModule = 'ContactFirstPage';
	new PAjax.Request('index.php', {
		method:'post',
		parameters: 'Message='+Object.toJSON(Message),
		onSuccess: function(t)
		{
			var MiniContact = t.responseText.evalJSON();
			$('MiniContactPhone').update(MiniContact.Phone);
			$('MiniContactEmail').update(MiniContact.Email);
			$('MiniContactAddress').update(MiniContact.Address);
		}
	})
    CM.loadModule('Modele');
});	
