/* 
 * novarising.com
 * @@ NovaRising, Copyright ©2009
 *
 */


 
/* A workaround for IE issues in mootools 1.2.1
 * - Recreates FX.Scroll() but utilises 1.2.0's getPosition/getOffset routines.
 */

Fx.Scroll2 = new Class({
 
    'Extends': Fx.Scroll,
 
    'styleString': Element.getComputedStyle,
    'styleNumber': function(element, style) {
        return this.styleString(element, style).toInt() || 0;
    },
    'borderBox': function(element) {
        return this.styleString(element, '-moz-box-sizing') == 'border-box';
    },
    'topBorder': function(element) {
        return this.styleNumber(element, 'border-top-width');
    },
    'leftBorder': function(element) {
        return this.styleNumber(element, 'border-left-width');
    },
    'isBody': function(element) {
        return (/^(?:body|html)$/i).test(element.tagName);
    },  
    'toElement': function(el) {
        var offset   = {x: 0, y: 0};
        var element  = $(el);
        
        if (this.isBody(element)) {
            return offset;
        }
        var scroll = element.getScrolls();
                
        while (element && !this.isBody(element)){
            offset.x += element.offsetLeft;
            offset.y += element.offsetTop;
            
            if (Browser.Engine.gecko){
                if (!this.borderBox(element)){
                    offset.x += this.leftBorder(element);
                    offset.y += this.topBorder(element);
                }
                var parent = element.parentNode;
                if (parent && this.styleString(parent, 'overflow') != 'visible'){
                    offset.x += this.leftBorder(parent);
                    offset.y += this.topBorder(parent);
                }
            } else if (Browser.Engine.trident || Browser.Engine.webkit){
                offset.x += this.leftBorder(element);
                offset.y += this.topBorder(element);
            }
 
            element = element.offsetParent;
            if (Browser.Engine.trident) {
                while (element && !element.currentStyle.hasLayout) {
                    element = element.offsetParent;
                }
            }
        }
        if (Browser.Engine.gecko && !this.borderBox(element)){
            offset.x -= this.leftBorder(element);
            offset.y -= this.topBorder(element);
        }

        
        var relative = this.element;
        var relativePosition = (relative && (relative = $(relative))) ? relative.getPosition() : {x: 0, y: 0};
        var position = {x: offset.x - scroll.x, y: offset.y - scroll.y};
        
        return this.start(position.x - relativePosition.x, position.y - relativePosition.y);
    }
});
 
 



var Site = {

	
	start: function(){
		


		var ie6 = false;
		if (navigator.appVersion.test('MSIE 6')) ie6 = true ;

		if (Browser.Engine.trident){
			Site.fixExplorer();
		}





		// pulse effect
		/*if ($('admin_header') && !$('subheaderadmin')){

			var pulseColors = new Array();
			pulseColors[0] = '#00BBBB';
			pulseColors[1] = '#53D3B3';
			pulseColors[2] = '#FF5D00';
			pulseColors[3] = '#D38788';
			pulseColors[4] = '#BDAF24';
			pulseColors[5] = '#59A3C1';


			nrPulseWhite = new Fx.Morph('admin_header', {
				duration:2400,
				transition:'expo:out',
				link: 'chain',
				fps:60
			});

			nrPulseRed = new Fx.Morph('admin_header', {
				duration:200,
				transition:'quint:in:out',
				link: 'chain',
				onComplete: function(){nrPulseWhite.start({'background-color': '#ffffff'});},
				fps:60
			});

			doPulse = function(){
				pulseColor = pulseColors[$random(0,pulseColors.length - 1)];
				nextTime = $random(3,20) * 1000;
				nrPulseRed.start({'background-color': pulseColor});
				t = setTimeout('doPulse();', nextTime);
			}

			var pulsate = (function(){doPulse();}).delay($random(1500,3000));

		}*/






		// add reflection to .reflect img tags
		if (!ie6) {
			$$('img').filter(function(img) { return img.hasClass("reflect"); }).reflect({'height': 0.2, 'opacity': 0.25});
			if($$('div.frontpageprojectslot_details')) $$('div.frontpageprojectslot_details').setStyle('margin-top', '-20px');
		}







		// header menu effect
		if($$('div#header ul li')){

			var mnuLi = $$('div#header ul li');
			var origWidth = new Array();
			var morphObject = new Array();
			var morphObjectOut = new Array();
			var yymorphObjectClick = new Array();

			mnuLi.each(function(e){

				if (e.id == 'mnu_logo') return false;

				origWidth[e.id] = e.getStyle('width');
				origWidth[e.id] = parseInt(origWidth[e.id].replace(/px/,''));

				morphObject[e.id] = new Fx.Morph(e, {
					duration:50,
					link: 'cancel',
					transition:'expo:in',
					fps:80
				});
				morphObjectOut[e.id] = new Fx.Morph(e, {
					duration:300,
					link: 'cancel',
					transition:'back:in',
					fps:80
				});


				e.addEvents({

					mouseenter: function(){
						if (e.getProperty('class') != 'clickedTopMenuObj'){
							/* e.setStyle('background-color', '#dd0000'); */
							e.setStyle('background-color', '#dd0000');
							e.setStyle('background-position', '0 65px');
							morphObject[e.id].start({
								'background-position': '0 54px'
							});
						}
					},

					mouseleave: function(){
						if (e.getProperty('class') != 'clickedTopMenuObj'){
							/*e.setStyle('background-color', '#dd0000');*/
							e.setStyle('background-color', '#dd0000');
							morphObjectOut[e.id].start({
								/*'background-color': '#c00000',*/
								'background-color': '#cc0000',
								'background-position': '0 65px'
							});
						}
					},

					click: function(){
						$$('.mnu_active').setProperty('class', '');
						e.setProperty('class', 'mnu_active');
					}

				});


			});
		} // header menu effect ends here



		// header submenu effect
		if($$('div#submenu ul li a')){

			curEffect = null;

			$$('div#submenu ul li a').each(function(e){
				e.set('tween', {duration:200, link:'chain'});
				e.addEvents({
					mouseenter: function(){
						if (e.getParent('li').getProperty('class') != 'sub_active')
						if(!Browser.Engine.trident) this.set('opacity', 0.6);
					},
					mouseleave: function(){
						if (e.getParent('li').getProperty('class') != 'sub_active')
//						if(!Browser.Engine.trident) curEffect = this.tween('opacity', 0.6, 1); // SCG: white over mid grey at 60% opacity looks green!
						if(!Browser.Engine.trident) this.set('opacity', 1);
					},
					click: function(ev){
						$$('.sub_active').setProperty('class', '');
						this.set('opacity', 1);
						e.getParent('li').setProperty('class', 'sub_active');
						// special manouvres for the project thumbnails:
						if(e.getParent('li').id.test(/^submenuProjectCategory/) && e.getProperty('class') != 'submenu_admin_icon'){
							if(ev) ev.stop();
							var clickedProjectCategory = e.getParent('li').id.replace(/submenuProjectCategory/, '');
							if (document.location.href.test(/http:\/\/.*\/projects\/view/))
								document.location.href = 'http://' + document.location.host + '/whatwehavedone/#' + clickedProjectCategory;
							else{
								location.hash = clickedProjectCategory; // in case they want to bookmark
								$$('.projectportfolio').each(function(prDiv){
									if(clickedProjectCategory > 0 && !prDiv.hasClass('projectcategory' + clickedProjectCategory)) prDiv.setStyle('display', 'none');
									prDiv.removeClass('last');
								});
								prDivCounter = 0;
								if (clickedProjectCategory > 0){
									$$('.projectcategory' + clickedProjectCategory).each(function(prDiv){
										if($(prDiv.id).getStyle('display') == 'none') projPortfolioFadeIn[prDiv.id].start('opacity', 0, 1);
										if(++prDivCounter % 3 == 0) prDiv.addClass('last');
									});
								} else {
									$$('.projectportfolio').each(function(prDiv){
										if($(prDiv.id).getStyle('display') == 'none') projPortfolioFadeIn[prDiv.id].start('opacity', 0, 1);
										if(++prDivCounter % 3 == 0) prDiv.addClass('last');
									});
								}
							}
						}
					}
				});
			});
			
			if($('submenuProjectCategory0') && document.location.href.split('#')[1] > 0){
				$('submenuProjectCategory0').removeClass('sub_active');
				$('submenuProjectCategory' + document.location.href.split('#')[1]).getElement('a').fireEvent('click');
			}
		}
		// header submenu effect ends here




		
		var checkHash = function(){
			if(!$('projectThumbs')) return;
			tabId = 'submenuProjectCategory' + location.hash.substring(1);
			if (tabId == 'submenuProjectCategory') tabId = 'submenuProjectCategory0';
			if($(tabId)) $(tabId).getElement('a').fireEvent('click');
			window.setTimeout(checkHash, 300);
		}


		// history for javascript project browsing
		if($('projectThumbs') && checkHash){


			checkHash();

		}







		// right list project images mouseover and click effect

		if ($$('.frontpageprojectslot') || $('projects_portfolio')){
			
			var projImgHoverEffectOut = new Array();

			if (!$('projects_portfolio'))
				imgList = $$('.frontpageprojectslot img');
			else
				imgList = $('projects_portfolio').getElements('img');


			imgList.each(function(img){
				projImgHoverEffectOut[img.id] =  new Fx.Tween(img, {
					duration:300,
					link: 'chain',
					transition: 'expo:in:out'
				});

				img.addEvents({
					mouseenter:function(){
						if(!(img.id)) return false;
						if(!ie6) img.setStyle('opacity', 0.75);
						if(!ie6 && img.parentNode.getElement('canvas')) img.parentNode.getElement('canvas').setStyle('opacity', 0.4);
						if($('clicktoenlarge')) $('clicktoenlarge').setStyle('color', '#CC0000').setStyle('background-position', '-977px 2px');
					},
					mouseleave:function(){
						if(!(img.id)) return false;
						if(!ie6) projImgHoverEffectOut[img.id].start('opacity',1);
						if(!ie6 && img.parentNode.getElement('canvas')) img.parentNode.getElement('canvas').tween('opacity', 1);
						if($('clicktoenlarge')) $('clicktoenlarge').setStyle('color', '#999999').setStyle('background-position', '-180px 2px');
					}
				});

			});
		} // right list project images mouseover & click effect ends here




		






		// project listing image mouseover
		if($('projectThumbs')){
			var projDescriptionSlide = new Array();
			var projPortfolioFadeIn = new Array();
			var projPortfolioFadeOut = new Array();
			$$('.projDescription').each(function(e){
				e.setStyle('visibility', 'visible');
				projDescriptionSlide[e.id] = new Fx.Slide(e.id, {
					duration: 150,
					fps: 90,
					link: 'chain',
					mode: 'horizontal',
					transition: Fx.Transitions.Expo.easeInOut
				});
				projDescriptionSlide[e.id].hide();
			});

			$$('.projectportfolio').each(function(e){
				projPortfolioFadeIn[e.id] = new Fx.Tween(e.id, {
					duration: 450,
					link: 'chain',
					fps: 90,
					transition: Fx.Transitions.Expo.easeInOut,
					onStart: function(ee){
						e.setStyle('opacity', 0);
						e.setStyle('display', 'block');
					}
				});
				/*
				projPortfolioFadeOut[e.id] = new Fx.Tween(e.id, {
					duration: 250,
					link: 'chain',
					fps: 90,
					transition: Fx.Transitions.Expo.easeInOut,
					onComplete: function(ee){
						e.setStyle('display', 'none');
					}
				});
				*/

				e.getElement('img').removeAttribute('title');
				e.getElement('img').removeAttribute('alt');
				if ($(e.id.replace(/projectportfolio/, 'projDescription')).innerHTML.length > 0){
					e.addEvents({
						mouseenter: function(ev){
							ev.stop();
							projDescriptionSlide[e.id.replace(/projectportfolio/, 'projDescription')].slideIn();
						},
						mouseleave: function(ev){
							ev.stop();
							projDescriptionSlide[e.id.replace(/projectportfolio/, 'projDescription')].slideOut();
						}
					});
					e.getElement('img').addEvents({
						click: function(ev){
							e.getElement('div[class=projDescription]').setStyle('background-color', '#CC0000').innerHTML = 'Opening...';
							var redirect = (function(){document.location = e.getElement('a');}).delay(150);
						}
					});
					e.getElement('div[class=projDescription]').addEvents({
						click: function(ev){
							ev.stop();
							this.setStyle('background-color', '#CC0000').innerHTML = 'Opening...';
							var redirect = (function(){document.location = e.getElement('a');}).delay(150);
						}
					});
				}
			});
		
		}





		// services expandables
		if($$('.crossesinterior') && $$('.crossesinteriordetails')){
			var crossesSlide = new Array();
			$$('.cross .crossesinteriordetails').each(function(e){
				crossesSlide[e.id] = new Fx.Slide(e.id, {
					duration: 400,
					fps: 90,
					link: 'cancel',
					transition: Fx.Transitions.Expo.easeInOut
				});
				crossesSlide[e.id].hide();
			});

			$$('.cross .crossesinterior').each(function(e){
					e.getElement('a').addEvents({
						mouseenter: function(ev){
							ev.stop();
							// close the rest
							hidId = e.id.replace(/crossesinterior/, 'crosseshidden');
							$$('.red').each(function(tcl){
									tcl.setProperty('class','cross');
									crossesSlide[tcl.id.replace(/crosses/, 'crosseshidden')].slideOut();
							});
							// open mine
							liId = e.id.replace(/interior/, '');
							$(liId).setProperty('class', 'red');
							crossesSlide[hidId].slideIn();
						},
						click: function(ev){
							myclass = e.parentNode.getProperty('class');
							hidId = e.id.replace(/crossesinterior/, 'crosseshidden');
							if(myclass == 'cross'){
								e.parentNode.setProperty('class','red');
								crossesSlide[hidId].slideIn();
							} else {
								e.parentNode.setProperty('class','cross');
								crossesSlide[hidId].slideOut();
							}
						}
					});
			});

			// ability to load a page with a slider open by default
			// http://www.novarising.com/departments/view/Usability+and+Design#18 ==> opens service with id=18 
			if ($('crossesinterior' + location.hash.substring(1))){
				if($('crossesinterior' + location.hash.substring(1)).getElement('a'))
					$('crossesinterior' + location.hash.substring(1)).getElement('a').fireEvent('click');
			}


		}
		// services expandables end here









		//htmlheaders/add image preview:
		if($('htmlheaderimagepreview') || $('clientimagepreview')){

			var comboBoxId = $('admImgListBlock').getElement('select').id;
			var imagePreviewId = '';
			if ($('htmlheaderimagepreview')) imagePreviewId = 'htmlheaderimagepreview';
			if ($('clientimagepreview')) imagePreviewId = 'clientimagepreview';
			var previewFileName = '';
			var picPreviewScroll = new Fx.Scroll2($(imagePreviewId), {
				duration: 200,
				wait: false,
				transition: 'back:in:out',
				fps:100
			});

			//pre-select a thumbnail on page load (for the admin_edit page):
			if ($(comboBoxId).selectedIndex > -1)
			picPreviewScroll.toElement($('cachedimg-' + $(comboBoxId).options[$(comboBoxId).selectedIndex].value));

			$(comboBoxId).addEvents({
				change: function(){
					if(Browser.Engine == 'webkit') return false;
					picPreviewScroll.toElement($('cachedimg-' + this.options[this.selectedIndex].value));
					$('editthisimage').getElement('a').setProperty('href', '/admin/images/edit/' + this.options[this.selectedIndex].value);
				}
			});	

			var clkIm = new Array();
			$(imagePreviewId).getElements('li').each(function(e){
					clkIm[e.id] = e.id.replace(/cachedimg-/, '');
					e.getElement('a').addEvents({
						click: function(){
							$(comboBoxId).getElements('option[value=' + clkIm[e.id] + ']').setProperty('selected', true);
							$(comboBoxId).fireEvent('change');
						}
					});
			});
		} //htmlheaders/add image preview ends here






		// actions links
		if ($$('div.actions')){
			var actionLinks = $$('div.actions ul li a');
			var idCnt = 0;
			var defaultBorderColor = new Array();
			actionLinks.each(function(e){
				thisId = 'actions_link_' + (idCnt++);
				e.setProperty('id', thisId);
				defaultBorderColor[e.id] = e.getStyle('border-bottom-color');
				
				morphObject[e.id] = new Fx.Morph(e, {
					duration:300,
					link: 'cancel',
					transition:'circ:in:out',
					fps:80
				});

				e.addEvents({
				
					mouseenter:function(){
						this.setStyle('border-bottom', '3px solid #cc0000');
					},
					mouseleave:function(){
						morphObject[e.id].start({
							'border-bottom-color': defaultBorderColor[e.id]
						});
					}
				});
				
			});
		} //actions links







		// form auto focus
		if($$('form')){
			if(errorbox = $$('form').getElement('input[class=form-error]')[0]) {
				try{
					errorbox.focus();
				} catch(err) {}
			} else if(inputbox = $$('form').getElement('input[type=text]')[0]){ 
				if(inputbox.id != 'ContactName'){
					try{
						inputbox.focus();
					} catch(err){}
				}
			}
		}






		// any questions box
		if($$('.anyquestionshidden') && $('anyquestions')){

			cntEl = 0;
			frmErrors = new Hash();
			$('ContactQuestion').set('tween', {duration:400, link:'cancel'});
			$('ContactName').set('tween', {duration:450, link:'cancel'});
			$('ContactEmail').set('tween', {duration:550, link:'cancel'});

			$('ContactAddForm').addEvents({
				submit: function(ev){
					ev.stop();
					$('ContactQuestion').fireEvent('validate');
					$('ContactName').fireEvent('validate');
					$('ContactEmail').fireEvent('validate');
					if (frmErrors.getLength() == 0){
						$('ContactAddForm').submit();
					} else {
						var errCounter = 0;
						frmErrors.each(function(hs, pm){
							$(pm).tween('background-color', '#FFCC00', '#CC0000');
							$(pm).setStyle('color', '#FFFFFF');
							$('ContactAddForm').getElement('label[for=' + pm + ']').innerHTML = hs;
							if(errCounter++ == 0) $(pm).focus();
						});
					}
				}
			});

			var questionsSlide = new Array();
			$$('.anyquestionshidden').each(function(e){
				if (!e.id) e.id = 'anyquestionshidden' + cntEl++;
				questionsSlide[e.id] = new Fx.Slide(e.id, {
					duration: 800,
					fps: 90,
					link: 'cancel',
					transition: Fx.Transitions.Bounce.easeOut
				});
				if($('ContactQuestion').value.length < 1) questionsSlide[e.id].hide();
				$('ContactQuestion').setStyle('overflow', 'hidden');
			});


			$('ContactQuestion').addEvents({

				blur: function(ev){
					this.setStyle('overflow', 'hidden');
					if (this.value.length <= 1) {
						$$('.anyquestionshidden').each(function(e){
							questionsSlide[e.id].slideOut();
						});
					}
				},
				lostfocus: function(ev){
					this.fireEvent('blur');
				},
				focus: function(ev){	
					this.setStyle('overflow', 'auto');
					$$('.anyquestionshidden').each(function(e){
						questionsSlide[e.id].slideIn();
					});
				},
				validate: function(ev){
					if(this.value.length < 3)
						frmErrors.set(this.id, 'Please type your question');
					else if(!this.value.test(/\b[a-zA-Z]{3,}\b/))
						frmErrors.set(this.id, 'Please type your question');
					else{
						frmErrors.erase(this.id);
						this.setStyle('background-color', '#FFFFFF');
						this.setStyle('color', '#000000');
					}
				}

			});

			$('ContactName').addEvents({
				focus: function(ev){
					$('ContactQuestion').fireEvent('focus');
				},
				blur: function(ev){
					$('ContactQuestion').fireEvent('blur');
				},
				validate: function(ev){
					if(this.value.length < 2)
						frmErrors.set(this.id, 'Please enter your name');
					else{
						frmErrors.erase(this.id);
						this.setStyle('background-color', '#FFFFFF');
						this.setStyle('color', '#000000');
					}
				}
			});

			$('ContactEmail').addEvents({
				focus: function(ev){
					$('ContactQuestion').fireEvent('focus');
				},
				blur: function(ev){
					$('ContactQuestion').fireEvent('blur');
				},
				validate: function(ev){
					frmErrors.erase(this.id);
					this.setStyle('background-color', '#FFFFFF');
					this.setStyle('color', '#000000');
					if(this.value.length > 0 && !this.value.test(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/))
						frmErrors.set(this.id, 'Invalid Email');
					else if(this.value.length == 0)
						frmErrors.set(this.id, 'Please enter your email');
				}
			});

			$('ContactPhone').addEvents({
				focus: function(ev){
					$('ContactQuestion').fireEvent('focus');
				},
				blur: function(ev){
					$('ContactQuestion').fireEvent('blur');
				}
			});

			$('ContactAddForm').getElement('input[type=submit]').addEvents({
				focus: function(ev){
					$('ContactQuestion').fireEvent('focus');
				},
				blur: function(ev){
					$('ContactQuestion').fireEvent('blur');
				}
			});


		}
		// end of any questions box










		// admin image filter
		if ($('admin_images_filter_form')){
			$('ImageImageTypeId').addEvents({
				change:function(){
					newtypeId = ($('ImageImageTypeId').options[$('ImageImageTypeId').options.selectedIndex].value);
					currentUrl = document.location.href;

					if (newtypeId != null){

						if (!currentUrl.test("/admin/images/index/", "i")) currentUrl = currentUrl.replace(/\/admin\/images/, "/admin/images/index");
						var newUrl = '';
						if(currentUrl.test("category:", "i")){
							newUrl = currentUrl.replace(/category:[0-9]*/i, "category:" + newtypeId);
						} else {
							newUrl = currentUrl + '/category:' + newtypeId;
						}
						
						newUrl = newUrl.replace(/\/\//, "/");
						newUrl = newUrl.replace(/\/\//, "/");
						newUrl = newUrl.replace(/http:\//, "http://");

					} else {

						newUrl = '/admin/images/index/'

					}

					document.location.href = newUrl;	
				}
			});
		}




		// hide - show relevant image fields "on add"
		if($('ImageImageTypeId') && $('admin_field_project_id') && $('admin_field_service_id')){

			var projSelectCombo = new Fx.Slide('admin_field_project_id', {
				duration: 200,
				fps: 80,
				transition: Fx.Transitions.Expo.easeOut
			});
			var deptSelectCombo = new Fx.Slide('admin_field_service_id', {
				duration: 200,
				fps: 80,
				transition: Fx.Transitions.Expo.easeOut
			});
			var prodSelectCombo = new Fx.Slide('admin_field_product_id', {
				duration: 200,
				fps: 80,
				transition: Fx.Transitions.Expo.easeOut
			});

			$('ImageImageTypeId').addEvents({
					change: function(){
						selectedImageType = $('ImageImageTypeId').options[$('ImageImageTypeId').options.selectedIndex].value;
						if(selectedImageType == 2 || selectedImageType == 4) {
							// the image is portfolio for project
							deptSelectCombo.slideOut();
							prodSelectCombo.slideOut();
							projSelectCombo.slideIn();
						} else if(selectedImageType == 5){
							// the image is related to departments
							projSelectCombo.slideOut();
							prodSelectCombo.slideOut();
							deptSelectCombo.slideIn();
						} else if(selectedImageType == 11){
							// the image is related to products
							prodSelectCombo.slideIn();
							projSelectCombo.slideOut();
							deptSelectCombo.slideOut();
						} else {
							// hide them all
							projSelectCombo.slideOut();
							deptSelectCombo.slideOut();
							prodSelectCombo.slideOut();
						}
					}
			});

			$('ImageImageTypeId').fireEvent('change');

		}


		






		// admin sortable clients and products
		if($('admin_clients_index') || $('admin_products_index') || $('admin_projects_index')){
			var orderedList;
			var model;

			if ($('admin_clients_index')){
				orderedList = $('admin_clients_index');
				model = 'clients';
			} else if($('admin_products_index')) {
				orderedList = $('admin_products_index');
				model = 'products';
			} else if($('admin_projects_index')){
				orderedList = $('admin_projects_index');
				model = 'projects';
			}
			
			orderedList.getElements('li').each(function(e){
					e.setStyle('cursor', 'move')
			});
			
			var startingPosition = 0;
			var finishingPosition = 0;
			var foundSortable = false;

			var sortableThingie = new Sortables('.sortable', {
				constrain: false,
				clone: true,
				
				revert: { duration: 500, transition: 'elastic:out' },
				onStart: function(e){
					foundSortable = false;
					e.setStyle('background-color', '#FF9900');
					startingPosition = e.getProperty('value');
				},
				onComplete: function(e){
					counter = 1;
					orderedList.getElements('li[alt=srt]').each(function(lie){
						if(lie.getProperty('value') == startingPosition)
						foundSortable = true;
						if(!foundSortable) counter++;
					});
					finishingPosition = counter;
					var id = e.getElement('a').getProperty('href').replace(/^.*edit\//, '');
					if (startingPosition == 0) return;
					var difference = finishingPosition - startingPosition;
					var movement = 'down';
					if(difference < 0) movement = 'up';
					var ajaxUrl = '/admin/' + model + '/' + movement + '/' + id + '/' + Math.abs(difference) + '/true';
					e.setStyle('background-color', '#FFFFFF');
					if($('loading')) $('loading').setStyle('visibility', 'visible');
					// do the ajax request
					var req = new Request({  
						url:ajaxUrl,  
						method:'get',  
						autoCancel:true,  
						onRequest: function() {  
							sortableThingie.detach();	
						},  
						onSuccess: function() {  
							// re-value the li items:
							counter = 1;
							orderedList.getElements('li[alt=srt]').each(function(lie){
								lie.setProperty('value', counter++);
							});
							sortableThingie.attach();	
							if($('loading')) $('loading').setStyle('visibility', 'hidden');
						}  
					}).send();  

				}

			});
		}



		

	}, // site start ends here
	

	fixExplorer: function(){
		$$('table').set('cellspacing', 0);
	}
	
};

window.addEvent('domready', function(){
	Site.start();
});


window.addEvent('load', function(){
});
