/**
 * @author rysiu
 */

var c5 = {
 	
	margin 		: [ 10, 0, 30, 0 ],
	site_margin : [ 10, 10, 30, 10 ],
	apla_margin : [ 10 ],
	min_width 	: 1200,
	min_height 	: 800,
	ie6			: false,
	
	init: function(domain) 
    {
		this.url = domain;
    },
    
    $: function(id) 
    {
		return document.getElementById(id);
    },

	getViewportSize: function () 
	{ 
		var size = [0, 0]; 	
		if (typeof window.innerWidth != "undefined") 
		{ 
			size = [window.innerWidth, window.innerHeight];
		} 
		else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth != 0) 
		{
			size = [document.documentElement.clientWidth, document.documentElement.clientHeight];
		}
		else
		{
			size = [document.getElementsByTagName("body")[0].clientWidth, document.getElementsByTagName("body")[0].clientHeight]; 
		}
		return size; 
	},
	
	getScrollerWidth : function() 
	{
	    var scr = null;
	    var inn = null;
	    var wNoScroll = 0;
	    var wScroll = 0;
	
	    // Outer scrolling div
	    scr = document.createElement('div');
	    scr.style.position = 'absolute';
	    scr.style.top = '-1000px';
	    scr.style.left = '-1000px';
	    scr.style.width = '100px';
	    scr.style.height = '50px';
	    // Start with no scrollbar
	    scr.style.overflow = 'hidden';
	
	    // Inner content div
	    inn = document.createElement('div');
	    inn.style.width = '100%';
	    inn.style.height = '200px';
	
	    // Put the inner div in the scrolling div
	    scr.appendChild(inn);
	    // Append the scrolling div to the doc
	    document.body.appendChild(scr);
	
	    // Width of the inner div sans scrollbar
	    wNoScroll = inn.offsetWidth;
	    // Add the scrollbar
	    scr.style.overflow = 'auto';
	    // Width of the inner div width scrollbar
	    wScroll = inn.offsetWidth;
	
	    // Remove the scrolling div from the doc
	    document.body.removeChild(
	        document.body.lastChild);
	
	    // Pixel width of the scroller
	    return (wNoScroll - wScroll);
	},
	
	createFullBrowserFlash : function () 
	{
		window.onresize = function() 
		{
			swfobject.createCSS("html", "overflow:hidden;");
			swfobject.createCSS("#conainter", "margin-top: 10px;");
			size 	= c5.getViewportSize();
			margin  = c5.margin;
						
			_top 	= margin[0];
			_right 	= margin[1];
			_bottom = margin[2];
			_left 	= margin[3];
			
			width 	= size[0] - (_right + _left);
			height 	= size[1] - (_top + _bottom);
			
			if(size[0] < c5.min_width || size[1] < c5.min_height)
			{
				swfobject.createCSS("html", "overflow:auto;");
				_scroll = c5.getScrollerWidth();
				if(size[0] < c5.min_width)
				{
					width  = ( c5.min_width - _scroll);
				}
				
				if (size[1] < c5.min_height)
				{
					height = (c5.min_height + _scroll);
					width = ( (size[0] < c5.min_width ? c5.min_width : size[0]) - (_right + _left) - _scroll);
				}
			}
 			c5.$("container").style.width = c5.$("apla").style.width = width + 'px';
			c5.$("container").style.height = c5.$("apla").style.height = height + 'px';
			c5.$("apla").style.width = width - 2 * c5.apla_margin[0] + 'px';
			
		};
		
		window.onresize();
	},
	
	createFullBrowser : function () 
	{
		window.onresize = function() 
		{
			swfobject.createCSS("#container", "overflow:hidden;");
			size 	= c5.getViewportSize();
			margin  = c5.site_margin;
						
			_top 	= margin[0];
			_right 	= margin[1];
			_bottom = margin[2];
			_left 	= margin[3];
			
			width 	= size[0] - (_right + _left);
			height 	= size[1] - (_top + _bottom);
			
			c5.$("container").style.width= c5.$("apla").style.width = 'auto';
			
			if(size[0] < c5.min_width || size[1] < c5.min_height)
			{
				_scroll = c5.getScrollerWidth();
				if(size[0] < c5.min_width)
				{
					c5.$("container").style.width = ( c5.min_width - ( _scroll)) + 'px';
					c5.$("apla").style.width = ( c5.min_width - _scroll - _right) + 'px';
				}
				
				if (size[1] < c5.min_height)
				{
					height = (c5.min_height + _scroll);
				}
			}
			c5.$("container").style.minHeight = c5.$("apla").style.minHeight = height + 'px';
			
			if(c5.ie6)
			{
				c5.$("container").style.height = c5.$("apla").style.height = height + 'px';
				c5.$("container").style.overflow = c5.$("apla").style.overflow = 'visible';
			}
			
		};
		
		window.onresize();
	}	
}