function windowSize() 
	{
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		}
		
		return new Array(myWidth, myHeight);
	}
	
	
	function posBackground()
	{
		var windowWH = windowSize();
		var windowWidth = windowWH[0];
		var windowHeight = windowWH[1];
		
		BackgroundWidth = 1920;
		BackgroundHeight = 1080;
		
		posTopBg = (BackgroundHeight - windowHeight) / 2;
		posLeftBg = (BackgroundWidth - windowWidth) / 2;
		
		return new Array(posTopBg, posLeftBg);	
	}
	
	
	function posContainer(posTopBg, posLeftBg)
	{
		posTopContainer = 210 - posTopBg;
		posLeftContainer = 220 - posLeftBg;
		
		return new Array(posTopContainer, posLeftContainer);
	}
	
	
	function posElements() 
	{
		var posBg = posBackground();
		var posTopBg = posBg[0];
		var posLeftBg = posBg[1];
		
		var posCont = posContainer(posTopBg, posLeftBg);
		var posTopContainer = posCont[0];
		var posLeftContainer = posCont[1];
		
		if(posTopContainer < 0)
		{
			posTopContainer = -20;
		}
		
		if(posLeftContainer < 0)
		{
			posLeftContainer = -20;
		}
		
		$("#background").animate( { top:(posTopBg * -1)+"px", left:(posLeftBg * -1)+"px" }, 1000);	
		$("#container").animate( { top:posTopContainer+"px", left:posLeftContainer+"px" }, 1500);	
	}


	function getNumber( min, max ) 
	{
        if( min > max ) {
            return( -1 );
        }
			
        if( min == max ) {
                return( min );
        }
        return( min + parseInt( Math.random() * ( max-min+1 ) ) );
	} 
	
	
	function changeBackground(changeFrequency)
	{
		var bgImage = new Array();
		var numBgImages = 6;
		for (var i = 1; i <= numBgImages; i++)
		{
			bgImage[i] = "images/bg/shop_bg_"+i+".jpg";
		}
		imgNumber = getNumber(1, numBgImages);
		document.getElementById("bgChange").src = bgImage[imgNumber];
		setTimeout("changeBackground("+changeFrequency+")", changeFrequency);
	}		

		var mousepos = new Array(null, null);

		
		$(document).ready( function () {
			// time to change BG Image (milliseconds) - 15000 for 15 secs
			var changeFrequency = 15000;
			
			//positionating all elements
			posElements();
			
			//making the background image draggable
			$("#background").draggable(
			{
				cursor: 'move', 
				revert: true,
				revertDuration: 400,
				drag: function(e)
				{
					if (mousepos[0] == null)
					{
						mousepos[0] = e.pageX;							
					}
					if (mousepos[1] == null)
					{
						mousepos[1] = e.pageY;
					}
					
					var versatz = posBackground();
					
					var maxDragY = versatz[0];
					var maxDragX = versatz[1];
					
					var startMouseX = mousepos[0];
					var startMouseY = mousepos[1];	
					
					var draggedX = e.pageX - startMouseX;
					var draggedY = e.pageY - startMouseY;
					
					if(draggedX > maxDragX || draggedX < (maxDragX * -1))
					{
						$('#background').DraggableDestroy();
					}
					
					if(draggedY > maxDragY || draggedY < (maxDragY * -1))
					{
						$('#background').DraggableDestroy();
					}
				},
				stop: function()
				{
					mousepos[0] = null;
					mousepos[1] = null;
				}
			}

			);
			
			//intialize the background-changer
			setTimeout("changeBackground("+changeFrequency+")", changeFrequency);
			
			//posElements() on resize event
			$(window).bind('resize', posElements);	

			//outgoing links
			
			$('a[rel="blank"]').click(function() { window.open(this.href); return false; });


		});
