var itemWidth = 171;
var itemInRow = 4;
var exampleFx = new Object();

var galleryLoad = function(){

if ($('hul').hasClass('some-line')){
	itemWidth = 684;
	itemInRow = 1;
	};


	 


var itemCount = $('hul').getChildren().length;
$('hul').setStyle('width', itemCount * itemWidth + "px");

//var curWidth = $('hul').getStyle('width', true).toInt();    
var curWidth = itemCount * itemWidth;    


Fx.Styles.implement({
    move: function(leftTo){
    	var curLeft = this.element.getStyle('left', true).toInt();
	
	if(leftTo < 0) // left
	{
	
	if (Math.abs(curLeft) + (itemWidth * itemInRow) < curWidth) {
			$('left_a').setOpacity(1);
			this.custom({'left': [curLeft, curLeft + leftTo]});
		}
		else {
			$('right_a').setOpacity(.5);	
		}
		
	}
	else //right
	{	
	if (curLeft != 0) {
			$('right_a').setOpacity(1);
			
			this.custom({'left': [curLeft, curLeft + leftTo]});
		}
		else {
			$('left_a').setOpacity(.5);	
		}
	}
	
	var cn = "f" + (((Math.abs(curLeft) + (itemWidth * itemInRow)) / 684) - 1);
	cn = cn.substring(0,2);
	$('pages').setProperty('class', cn);
	
	}	
    
});

exampleFx = new Fx.Styles('hul',  {duration: 300, transition: Fx.Transitions.linear});







for (var i = 0, y = 0, z = itemCount; i < z; i = i+itemInRow, y++){
  		var page = new Element("a");
  		page.setHTML(y + 1);
  		page.setProperty('class', "f" + y);
  		page.addEvent('click', function(){
			
			if($('pages')) $('pages').setProperty('class', this.className);
			$('right_a').setOpacity(1);
			$('left_a').setOpacity(1);
			
			
			
		 $('hul').effect('left',{
		 duration: 500,
		 transition: Fx.Transitions.linear
		 }).start(itemWidth * -itemInRow * this.className.replace("f", ""));	
			});
			
  		page.injectInside('pages');
}
}



var customTipsLoad = function(targ, classN, offs){
Tips.implement({
	build: function(el){
		el.$tmp.myTitle = (el.href && el.getTag() == 'a') ? el.href.replace('http://', '') : (el.rel || false);
		if (el.title){
			var dual = el.title.split('::');
			if (dual.length == 3){
				el.$tmp.myTitle = dual[0].trim();
				el.$tmp.myText = dual[1].trim() + "<br />" + dual[2].trim();
			} else if (dual.length == 2){
				el.$tmp.myTitle = dual[0].trim();
				el.$tmp.myText = dual[1].trim();
			} else {
			  el.$tmp.myTitle = el.title;
				el.$tmp.myText = "&#160;";
			}
			el.removeAttribute('title');
		} else {
			el.$tmp.myText = false;
		}
		if (el.$tmp.myTitle && el.$tmp.myTitle.length > this.options.maxTitleChars) el.$tmp.myTitle = el.$tmp.myTitle.substr(0, this.options.maxTitleChars - 1) + "&hellip;";
		el.addEvent('mouseenter', function(event){
			this.start(el);
			if (!this.options.fixed) this.locate(event);
			else this.position(el);
		}.bind(this));
		if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
		var end = this.end.bind(this);
		el.addEvent('mouseleave', end);
		el.addEvent('trash', end);
	},
	locate: function(event){
		var win = {'x': window.getWidth(), 'y': window.getHeight()};
		var scroll = {'x': window.getScrollLeft(), 'y': window.getScrollTop()};
		var tip = {'x': this.toolTip.offsetWidth, 'y': this.toolTip.offsetHeight};
		this.options.offsets['y'] = -1 * (tip['y'] + 10);
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = event.page[z] + this.options.offsets[z];
			if ((pos + tip[z] - scroll[z]) > win[z]) pos = event.page[z] - this.options.offsets[z] - tip[z];
			this.toolTip.setStyle(prop[z], pos);
		};
	}
});
var myTips = new Tips($$(targ), {
	maxTitleChars: 100,
	offsets: offs,
	className : classN
});
}


Element.extend({
	effect: function(property, options){
        return new Fx.Style(this, property, options);
    }
    });
    
var projectGalleryLoad = function()
{
var galleryHeight = ($('project-gallery').getChildren().length - 1) * 356;
  $('shirm').effect('opacity',{duration: 400}).start(1,0);
  $('shirm').setStyle('background', '#fff');
  $('controls').setStyle('display', 'block');	
	if($('moreLink')) {$('moreLink').onmouseover = function(){$('more').effect('width').start(45, 114).chain(function(){$('moreLink').effect('color').start('839099','ffffff')});}}
	
	if($('moreLink')) {$('moreLink').onmouseout = function(){this.effect('color', {duration: 200}).start('ffffff', '839099').chain(function(){$('more').effect('width', {duration: 200}).start(114,45)});}}

	if($('moreLink')) {$('moreLink').onclick = function(){$('info').effect('left').start(-274, 0).chain(function(){$('close').effect('opacity').start(0,1)}); return false;}}
	$('close').onclick = function(){$('close').effect('opacity').start(1,0).chain(function(){$('info').effect('left').start(0, -274)}); return false;}

	$('nextLink').onclick = function(){
	  var curTop = $('project-gallery').getStyle('top', true).toInt();
	  if(Math.abs(curTop) < galleryHeight){
	    tempTop = curTop - 356;
	  }
	  else{
	    tempTop = 0;
	  }
	  $('shirm').effect('opacity', {duration: 400}).start(0, 1).chain(function(){
	      $('project-gallery').effect('top', {duration: 0}).start(curTop, tempTop).chain(function(){
		$('shirm').effect('opacity',{duration: 400}).start(1,0)
		})
	      });
	  return false;
	}


	$('prevLink').onclick = function(){
	  var curTop = $('project-gallery').getStyle('top', true).toInt();
	  if(Math.abs(curTop) != 0){
	    tempTop = curTop + 356;
	  }
	  else{
	    tempTop = galleryHeight * -1;
	  }
	  $('shirm').effect('opacity', {duration: 400}).start(0, 1).chain(function(){
	      $('project-gallery').effect('top', {duration: 0}).start(curTop, tempTop).chain(function(){
		$('shirm').effect('opacity', {duration: 400}).start(1,0)
		})
	      });
	  return false;
	}

}

var homePageAn = function(){
//$E('strong.linked', 'content-secondary').addEvent('mouseover', function(){$(this.parentNode).addClass('over')});
//$E('strong.linked', 'content-secondary').addEvent('mouseout', function(){$(this.parentNode).removeClass('over')});
}

