/* -----------------------------------------------------------------

	ATTACH MOCHA LINK EVENTS
	Notes: Here is where you define your windows and the events that open them.
	If you are not using links to run Mocha methods you can remove this function.
	
	If you need to add link events to links within windows you are creating, do
	it in the onContentLoaded function of the new window.

   ----------------------------------------------------------------- */

function attachMochaLinkEvents(){

	if ($$('.mootoolsLink')){
		$$('.mootoolsLink').addEvent('click', function(e){
			var rootId = document.getElementById('books');
			var childId = rootId.getElementsByTagName("a");
			for(i=0;i<childId.length;i++){
				if(childId[i].rel.substr(0,1)=='1'){
				//	alert("Aktywny");
					var urlAct = childId[i].rel.substr(2);
				}
			}
                        var nx = Math.ceil(Math.random()*(document.body.clientWidth-300));
                        var ny = Math.ceil(Math.random()*(document.body.clientHeight-245))+70;
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'mootools' + urlAct,
				title: 'Ebook informacje',
				loadMethod: 'iframe',
				contentURL: 'pages/ebook.php?id=' + urlAct,
				width: 300,
				height: 190,
				scrollbars: false,
				paddingVertical: 0,
				paddingHorizontal: 0,
                                resizable: false,
                                x: nx,
                                y: ny
			});
		});
	} 
        
/*        window.addEvent('domready', function(){
                if(document.getElementById('books')!=null){
                        var rootId = document.getElementById('books');
                        var childId = rootId.getElementsByTagName("a");
                        for(i=0;i<childId.length;i++){
                                var urlAct = childId[i].rel.substr(2);
                                var nx = Math.ceil(Math.random()*(document.body.clientWidth-300));
                                var ny = Math.ceil(Math.random()*(document.body.clientHeight-245))+70;
                        //        new Event(e).stop();
                                document.mochaUI.newWindow({
                                        id: 'mootools' + urlAct,
                                        title: 'Ebook informacje',
                                        loadMethod: 'iframe',
                                        contentURL: 'pages/ebook.php?id=' + urlAct,
                                        width: 300,
                                        height: 190,
                                        scrollbars: false,
                                        paddingVertical: 0,
                                        paddingHorizontal: 0,
                                        resizable: false,
                                        x: nx,
                                        y: ny
                                });   
                        }
                        document.mochaUI.arrangeCascade();
                }
        })
*/

	// View
	if ($('cascadeLink')){
		$('cascadeLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.arrangeCascade();
		});
	}
	
	if ($('closeLink')){
		$('closeLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.closeAll();
		});
	}	
	
	// Workspaces	
	if ($('workspace01Link')){
		$('workspace01Link').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaScreens.setScreen(0)
		});
	}
	
	if ($('workspace02Link')){
		$('workspace02Link').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaScreens.setScreen(1)
		});
	}
	
	if ($('workspace03Link')){
		$('workspace03Link').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaScreens.setScreen(2)
		});
	}	
	
	// Help
	if ($('faqLink')){
		$('faqLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'faq',
				title: 'FAQ',
				loadMethod: 'xhr',
				contentURL: 'pages/faq.html',
				width: 320,
				height: 320,
				x: 20,
				y: 70
			});
		});
	}   
        
        if ($('historia')){
		$('historia').addEvent('click', function(e){
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'historiaX',
				title: 'Historia rachunków',
				loadMethod: 'iframe',
				contentURL: 'pages/historia.php',
				width: 300,
				height: 190,
				scrollbars: false,
				paddingVertical: 0,
				paddingHorizontal: 0,
                                resizable: true,
                                x: 10,
                                y: 80
			});
		});
	}
        
        if ($('wyniki')){
		$('wyniki').addEvent('click', function(e){
                        var dt = document.getElementById('datatime').value;
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'historiaA',
				title: 'Generowanie rachunków',
				loadMethod: 'iframe',
				contentURL: 'pages/historia.php?dt=' + dt,
				width: 300,
				height: 190,
				scrollbars: false,
				paddingVertical: 0,
				paddingHorizontal: 0,
                                resizable: true,
                                x: 30,
                                y: 110
			});
		});
	}
	
	if ($$('.docsLink')){
		$$('.docsLink').addEvent('click', function(e){
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'docs',
				title: 'Documentation',
				loadMethod: 'xhr',
				contentURL: 'pages/docs.html',
				width: 600,
				height: 350,
				x: 20,
				y: 70
			});
		});
	}
	
	if ($('overviewLink')){
		$('overviewLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'overview',
				title: 'Overview',
				loadMethod: 'xhr',
				contentURL: 'pages/overview.html',
				width: 300,
				height: 255,
				x: 20,
				y: 70
			});
		});
	}

	if ($('resourcesLink')){
		$('resourcesLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'resources',
				title: 'Resources',
				loadMethod: 'xhr',
				contentURL: 'pages/resources.html',
				width: 300,
				height: 275,
				x: 20,
				y: 70
			});
		});
	}
	
	if ($('helpLink')){
		$('helpLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'help',
				title: 'Support',
				loadMethod: 'xhr',
				contentURL: 'pages/support.html',
				width: 320,
				height: 320,
				x: 20,
				y: 70
			});
		});
	}
	
	if ($('contributeLink')){
		$('contributeLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'contribute',
				title: 'Contribute',
				loadMethod: 'xhr',
				contentURL: 'pages/contribute.html',
				width: 320,
				height: 320,
				x: 20,
				y: 70
			});
		});
	}	
	
	if ($('aboutLink')){
		$('aboutLink').addEvent('click', function(e){	
			new Event(e).stop();
			document.mochaUI.newWindow({
				id: 'about',
				title: 'Mocha UI Version 0.8',
				loadMethod: 'xhr',
				contentURL: 'pages/about.html',
				modal: true,
				width: 300,
				height: 150
			});
		});
	}

	// Deactivate menu header links
	$$('a.returnFalse').each(function(el){
		el.addEvent('click', function(e){
			new Event(e).stop();
		});
	});
	
}