$(document).ready(function() {  	 
	
	prepareSection('#developers-eff-adv-text');			
	prepareSection('#developers-eff-id-text');

	prepareSection('#investments-eff-adv-text');			
	prepareSection('#investments-eff-id-text');	
	prepareSection('#developers-media-pr-text');
	prepareSection('#developers-media-str-text');
	prepareSection('#developers-media-str-text');
	prepareSection('#production-column-1-body');
	

	$('#top').append('<div id="gotohome-r"></div>');
	
	if ($('#top').attr('class') != 'wotext')		
		$('#top').append('<div id="gotohome-t">home &raquo;</div>');
		
	$('#gotohome-r').bind('click', function() {
		window.location='index.php';
	});
	
	$('#top-menu .selected').mouseover(function() {
		$(this).css('font-size', '13px');
	});
	
	$('.next-prev').prepend('<span class="switch next">więcej</span>');
	
	
	$('#type-buttons .row').bind('click', function() {
		var id = $(this).attr('id');
		switch(id.substring(7, id.length)) {
			case 'introligatornia':
				window.location='index.php?page=production&subpage=introligatornia';
			break;
			case 'przygotowalnia':
				window.location='index.php?page=production&subpage=przygotowalnia';
			break;
			case 'druk-arkuszowy':
				window.location='index.php?page=production&subpage=da';
			break;	
			case 'druk-rolowy':
				window.location='index.php?page=production&subpage=dr';
			break;														
		}
	});
	
	$('#type-images .row img').bind('click', function() {
		var id = $(this).attr('id');
		switch(id.substring(4, id.length)) {
			case 'introligatornia':
				window.location='index.php?page=produkcja&subpage=introligatornia';
			break;
			case 'przygotowalnia':
				window.location='index.php?page=produkcja&subpage=przygotowalnia';
			break;
			case 'druk-arkuszowy':
				window.location='index.php?page=produkcja&subpage=da';
			break;	
			case 'druk-rolowy':
				window.location='index.php?page=produkcja&subpage=dr';
			break;														
		}
	});			
	
	
	$('#type-buttons .row').mouseover(function() {
		$(this).css('background', '#3d517c');
		var id = $(this).attr('id');
		var imgId = "#img-" + id.substring(7, id.length);
		$(imgId).attr('src', '../images/produkcja/' + id.substring(7, id.length) + "-on.jpg");
	});

	$('#type-buttons .row').mouseout(function() {
		$(this).css('background', '#9aa4bb');
		var id = $(this).attr('id');
		var imgId = "#img-" + id.substring(7, id.length);
		$(imgId).attr('src', '../images/produkcja/' + id.substring(7, id.length) + "-off.jpg");		
	});	
	
	$('#type-images .row img').mouseover(function() {
		var id = $(this).attr('id');
		$(this).attr('src', '../images/produkcja/' + id.substring(4, id.length) + "-on.jpg");		
		var buttonId = "#button-" + id.substring(4, id.length);
		$(buttonId).css('background', '#3d517c');
	});	
	
	$('#type-images .row img').mouseout(function() {
		var id = $(this).attr('id');
		$(this).attr('src', '../images/produkcja/' + id.substring(4, id.length) + "-off.jpg");		
		var buttonId = "#button-" + id.substring(4, id.length);
		$(buttonId).css('background', '#9aa4bb');
	});		


	$('#developers-eff-id-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#developers-eff-id-button').mouseout(function() {
		$(this).css('background', '#ddd');
	});
	
	$('#developers-eff-adv-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#developers-eff-adv-button').mouseout(function() {
		$(this).css('background', '#ddd');
	});	
	
	
	$('#investments-eff-id-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#investments-eff-id-button').mouseout(function() {
		$(this).css('background', '#ddd');
	});
	
	
	$('#investments-eff-adv-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#investments-eff-adv-button').mouseout(function() {
		$(this).css('background', '#ddd');
	});	
	
	$('#developers-media-str-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#developers-media-str-button').mouseout(function() {
		$(this).css('background', '#ddd');
	});		
	
	
	$('#developers-media-pr-button').mouseover(function() {
		$(this).css('background', '#ccc');
	});
	
	$('#developers-media-pr-button').mouseout(function() {
		$(this).css('background', '#EEEEEE');
	});		
							
	
	$('.next-prev img').bind('click', function() {
		var vClass = $(this).attr('class');
		if (vClass == 'next') {
			if ($(this).attr('id') == 'c1') {
				$(this).attr('class', 'prev');
				$(this).attr('src', 'images/prev-small.jpg');				
			} else {
				$(this).attr('class', 'prev');
				$(this).attr('src', 'images/prev.jpg');				
			}
			
		}
		if (vClass == 'prev') {
			if ($(this).attr('id') == 'c1') {
				$(this).attr('class', 'next');
				$(this).attr('src', 'images/next-small.jpg');				
			} else {
				$(this).attr('class', 'next');
				$(this).attr('src', 'images/next.jpg');				
			}
		}
	});	
		
	$(".menu-pos").mouseover(function() {
		var id = $(this).attr('id');
			if ($('#' + id + ' img').css('display') == 'none')
	      		$("#" + id + " > .image > img").queue(function () {
	        		$(this).fadeIn("fast");
	        		$(this).dequeue();
	      		});		

			$("#" + id + " h1").css('color', '#fff');
	});
	
	$(".menu-pos").bind('mouseleave', function() {
		var id = $(this).attr('id');
		if ($('#' + id + ' img').css('display') == 'inline')
	      $("#" + id + " > .image > img").queue(function () {
	        $(this).fadeOut("fast");
	        $(this).dequeue();
	      });		
		$("#" + id + " h1").css('color', '#ccc');
	});	
		
	/* main menu controls */
	$('#developers').bind('click', function() {
		window.location='?page=developers';
	});
	$('#creation').bind('click', function() {
		//window.location='?page=creation';
		window.location='/www/brightness.html';
	});	
	$('#production').bind('click', function() {
		window.open("http://www.i-brightness.pl", "_self");
	});		
	
	/** dev-menu-controls **/
	
	$("#developers-wrapper #content #column-2 .menu .menu-pos").bind('mouseenter', function() {
		$(this).css('background', '#dadada');
		var name = $(this).attr('id');
		var imageid = "image-" + name.substring(5, name.length);
			$("#" + imageid).fadeTo("fast", 1);
			return;
				
	});
	$("#developers-wrapper #content #column-2 .menu .menu-pos").bind('mouseleave', function() {
		$(this).css('background', 'none');
		var name = $(this).attr('id');
		var imageid = "image-" + name.substring(5, name.length);
			$("#" + imageid).fadeTo("fast", 0.5);
			return;
	});	
		
	
	$("#developers-wrapper #content #image-mosaic img").bind('mouseenter', function() {
		var name = $(this).attr('id');
		
		var menuid = "menu-" + name.substring(6, name.length);
		$('#' + menuid).css('background', '#dadada');
		if ($(this).css('opacity') == 0.5)		
			$(this).fadeTo("fast", 1);
		
	});	
	
	$("#developers-wrapper #content #image-mosaic img").bind('mouseleave', function() {
		var name = $(this).attr('id');
		var menuid = "menu-" + name.substring(6, name.length);		
		$('#' + menuid).css('background', '');
			$(this).fadeTo("fast", 0.5);
		
	});	
	
	$('#menu-wd').bind('click', function() {
		window.location='?page=developers&subpage=picture';
	});	
	$('#menu-wi').bind('click', function() {
		window.location='?page=developers&subpage=investition';
	});		
	$('#menu-mip').bind('click', function() {
		window.location='?page=developers&subpage=media';
	});	
	$('#menu-mwp').bind('click', function() {
		window.location='?page=developers&subpage=materials';
	});		
	
	/** animation for developer egg **/
	$('#developers-eff-adv-button').bind('click', function() {
		$('#column-1 .text').html('Właściwy wizerunek to klucz do sukcesu Twojej firmy');
		$('#developers-eff-id-button .image').fadeTo('fast', 0.3);
		$('#developers-eff-adv-button .image').fadeTo('fast', 1);
		if ($('#developers-eff-basic-text').css('display') != 'none') {
			$('#developers-eff-basic-text').fadeOut('fast', function() {
				$('#developers-eff-adv-text').fadeIn('fast');
			});
		} else {
			$('#developers-eff-id-text').fadeOut('fast', function() {
				$('#developers-eff-adv-text').fadeIn('fast');
			});			
		}
	});
	
	$('#developers-eff-id-button').bind('click', function() {
		$('#column-1 .text').html('Jeśli chcesz odnieść sukces, musisz wyglądać profesjonalnie');		
		$('#developers-eff-adv-button .image').fadeTo('fast', 0.3);
		$('#developers-eff-id-button .image').fadeTo('fast', 1);
		if ($('#developers-eff-basic-text').css('display') != 'none') {
			$('#developers-eff-basic-text').fadeOut('fast', function() {
				$('#developers-eff-id-text').fadeIn('fast');
			});
		} else {
			$('#developers-eff-adv-text').fadeOut('fast', function() {
				$('#developers-eff-id-text').fadeIn('fast');
			});			
		}
	});	
	
	
	/** animation for developer inv **/
	$('#investments-eff-adv-button').bind('click', function() {
		$('#column-1 .text').html('By sprzedać musisz zaoferować właściwy produkt, właściwym ludziom');				
		$('#investments-eff-id-button .image').fadeTo('fast', 0.3);
		$('#investments-eff-adv-button .image').fadeTo('fast', 1);
		if ($('#investments-eff-basic-text').css('display') != 'none') {
			$('#investments-eff-basic-text').fadeOut('fast', function() {
				$('#investments-eff-adv-text').fadeIn('fast');
			});
		} else {
			$('#investments-eff-id-text').fadeOut('fast', function() {
				$('#investments-eff-adv-text').fadeIn('fast');
			});			
		}
	});
	
	$('#investments-eff-id-button').bind('click', function() {	
		$('#column-1 .text').html('Przemawiamy do wszystkich zmysłów klientów');						
		$('#investments-eff-adv-button .image').fadeTo('fast', 0.3);
		$('#investments-eff-id-button .image').fadeTo('fast', 1);
		if ($('#investments-eff-basic-text').css('display') != 'none') {
			$('#investments-eff-basic-text').fadeOut('fast', function() {
				$('#investments-eff-id-text').fadeIn('fast');
			});
		} else {
			$('#investments-eff-adv-text').fadeOut('fast', function() {
				$('#investments-eff-id-text').fadeIn('fast');
			});			
		}
	});		
	
	/** animation for developer media **/
	$('#developers-media-str-button').bind('click', function() {
		$('#column-1 .text').html('Strategia to nic innego, jak gruntowne przygotowanie do bitwy');	
		$('#developers-media-pr-button').fadeTo('fast', 0.3);
		$('#developers-media-pl-button').fadeTo('fast', 0.3);
		$('#developers-media-str-button').fadeTo('fast', 1);
		
		$('#developers-media-str-button').css('background-color', '#b4c0d5');
		$('#developers-media-pl-button').css('background-color', '#EEE');
		$('#developers-media-pr-button').css('background-color', '#EEE');
		
		if ($('#developers-media-basic-text').css('display') != 'none') {
			$('#developers-media-basic-text').fadeOut('fast', function() {
				$('#developers-media-str-text').fadeIn('fast');
			});
		} else if ($('#developers-media-pr-text').css('display') != 'none') {
			$('#developers-media-pr-text').fadeOut('fast', function() {
				$('#developers-media-str-text').fadeIn('fast');
			});			
		} else {
			$('#developers-media-pl-text').fadeOut('fast', function() {
				$('#developers-media-str-text').fadeIn('fast');
			});	
		}
	});
	
	$('#developers-media-pr-button').bind('click', function() {
		$('#column-1 .text').html('Działania PR zbudują zaufanie do Twojej inwestycji');			
		$('#developers-media-str-button').fadeTo('fast', 0.3);
		$('#developers-media-pl-button').fadeTo('fast', 0.3);
		$('#developers-media-pr-button').fadeTo('fast', 1);
		
		$('#developers-media-pr-button').css('background-color', '#b4c0d5');
		$('#developers-media-pl-button').css('background-color', '#EEE');
		$('#developers-media-str-button').css('background-color', '#EEE');
		
		if ($('#developers-media-basic-text').css('display') != 'none') {
			$('#developers-media-basic-text').fadeOut('fast', function() {
				$('#developers-media-pr-text').fadeIn('fast');
			});
		} else if ($('#developers-media-str-text').css('display') != 'none') {
			$('#developers-media-str-text').fadeOut('fast', function() {
				$('#developers-media-pr-text').fadeIn('fast');
			});			
		} else {
			$('#developers-media-pl-text').fadeOut('fast', function() {
				$('#developers-media-pr-text').fadeIn('fast');
			});	
		}
	});	
	
	$('#developers-media-pl-button').bind('click', function() {
		
		$('#developers-media-str-button').fadeTo('fast', 0.3);
		$('#developers-media-pr-button').fadeTo('fast', 0.3);
		$('#developers-media-pl-button').fadeTo('fast', 1);
		
		$('#developers-media-pl-button').css('background-color', '#b4c0d5');
		$('#developers-media-pr-button').css('background-color', '#EEE');
		$('#developers-media-str-button').css('background-color', '#EEE');
		
		if ($('#developers-media-basic-text').css('display') != 'none') {
			$('#developers-media-basic-text').fadeOut('fast', function() {
				$('#developers-media-pl-text').fadeIn('fast');
			});
		} else if ($('#developers-media-str-text').css('display') != 'none') {
			$('#developers-media-str-text').fadeOut('fast', function() {
				$('#developers-media-pl-text').fadeIn('fast');
			});			
		} else {
			$('#developers-media-pr-text').fadeOut('fast', function() {
				$('#developers-media-pl-text').fadeIn('fast');
			});	
		}
	});		
	/***************************************************/
	var selectedId = "";
	
	$('#developers-subpage-materials-wrapper #content .menu .menu-pos').bind('mouseenter', function() {
		if($(this).attr('id') != selectedId)
			$(this).css('background', '#406888');
	});
	$('#developers-subpage-materials-wrapper #content .menu .menu-pos').bind('mouseleave', function() {
		if($(this).attr('id') != selectedId)
			$(this).css('background', '');
	});	
	$('#developers-subpage-materials-wrapper #content .menu .menu-pos').bind('click', function() {
		
		/* hide old text */
		if (selectedId != "") {
			var textToHide = "#text-" + selectedId.substr(5,selectedId.length); 	
		} else {
			var textToHide = "#text-basic";
		}
		
		var newId = $(this).attr('id')
		
		$(textToHide).fadeOut("fast", function() {
			$("#text-" + newId.substr(5,newId.length)).fadeIn("fast");
		});		
			
		selectedId = newId;
		
		$(this).css('background', '#9dacb8');
		
		/** clear another selections **/
		var menuPoses =  $('#developers-subpage-materials-wrapper #content .menu .menu-pos');
		for(var i = 0; i < menuPoses.length; i++) {
			if ( $(menuPoses[i]).attr('id') != selectedId )
			 	$(menuPoses[i]).css('background', '');
		}
	});
	
	/***************************************************/
	$('#creation-wrapper #content .menu .menu-pos').bind('mouseenter', function() {
		if($(this).attr('id') != selectedId) {
			$(this).css('background', '#632637');
			var al = "#" + $(this).attr('id') + " a";
			$(al).css('color', '#fff');
		}
	});
	$('#creation-wrapper #content .menu .menu-pos').bind('mouseleave', function() {
		if($(this).attr('id') != selectedId) {
			$(this).css('background', '');
			var al = "#" + $(this).attr('id') + " a";
			$(al).css('color', '#000');
		}
	});		
		
});

function prepareSection(pContainer) {
			$(pContainer).serialScroll({
				target:'#sections',
				items:'li.section', //selector to the items ( relative to the matched elements, '#sections' in this case )
				prev:'img.prev',//selector to the 'prev' button (absolute!, meaning it's relative to the document)
				next:'img.next',//selector to the 'next' button (absolute too)
				axis:'x',//the default is 'y'
				queue:false,//we scroll on both axes, scroll both at the same time.
				event:'click',//on which event to react (click is the default, you probably won't need to specify it)
				stop:false,//each click will stop any previous animations of the target. (false by default)
				lock:true, //ignore events if already animating (true by default)
				duration:700,//length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
				start: 0, //on which element (index) to begin ( 0 is the default, redundant in this case )
				force:true, //force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
				cycle:true,//cycle endlessly ( constant velocity, true is the default )
				step:1, //how many items to scroll each time ( 1 is the default, no need to specify )
				jump:false, //if true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
				lazy:false,//(default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
				interval:false, //it's the number of milliseconds to automatically go to the next
				navigation:'#navigation li',
				constant:true,
				onBefore:function( e, elem, $pane, $items, pos ){
					/**
					 * 'this' is the triggered element 
					 * e is the event object
					 * elem is the element we'll be scrolling to
					 * $pane is the element being scrolled
					 * $items is the items collection at this moment
					 * pos is the position of elem in the collection
					 * if it returns false, the event will be ignored
					 */
					 //those arguments with a $ are jqueryfied, elem isn't.
					e.preventDefault();
					if( this.blur )
						this.blur();
				},
				onAfter:function( elem ){
					//'this' is the element being scrolled ($pane) not jqueryfied
				}
			});
}