jQuery.rtl = {
	indexInit : function(calcUrl, serviceUrl, reviewUrl) {
		$('.slideshow').cycle({
			fx: 'fade'
		});

		$('.current-service').die('click').live('click', function (obj) {
			obj.preventDefault(); 
			$("#current-service").load(serviceUrl, {
				id: this.id || this.rel
			}, function() {
				$('#current-service-window').dialog({
					bgiframe: true,
					height: 300,
					width: 600,
					modal: true
				});
			});			
		});	
		
		$('.current-review').die('click').live('click', function (obj) {
			obj.preventDefault(); 
			$("#current-review").load(reviewUrl, {
				id: this.id || this.rel
			}, function() {
				$('#current-review-window').dialog({
					bgiframe: true,
					height: 300,
					width: 600,
					modal: true
				});
			});			
		});	
	
		$('#calculator').bind('submit', function() {
			$("#load").load(calcUrl, {
				price: this.price.value
			}, function() {
				$('#more-solutions').dialog({
					bgiframe: true,
					autoOpen: false,
					width: 600,
					modal: true
				});

				$('#more-solutions-link').click(function(){
					$('#more-solutions').dialog('open');
					return false;
				});				
			});			
			return false;
		});
		
		$("#services-panel").scrollable({
			size: 3,
			clickable: false
		}).circular().mousewheel();

		$('#photos').galleryView( {
			border : 'none',
			panel_width : 990,
			panel_height : 371,
			frame_width : 100,
			frame_height : 100
		});

		
	},

	contactsInit : function() {
		$('.contacts dd input, .contacts dd textarea').focus(function(){
			$(this).addClass('activeField');
		});
		
		$('.contacts dd input, .contacts dd textarea').blur(function(){
			$(this).removeClass('activeField');
		});
				
		$('.kwicks').kwicks( {
			max : 320,
			sticky : true,
			spacing : 5
		});

		$.myEngine.form("#contactsForm");
	},

	
	encode: function(hash) {		
		if($.browser.msie) {
			hash = encodeURIComponent(hash);
			hash = hash.replace(/%2F/gi, '/');
			hash = hash.replace(/%2B/gi, '+');
		}
		return hash;
	},
	
	
	articlesInit : function(url) {		
		$.historyInit(function(hash) {
			hash = hash || url;
			$("#load").load($.rtl.encode(hash), {}, function() {
				$("a[rel='ajax']").click(function() {
					var hash = this.href;
					hash = hash.replace(/%20/gi, '+');
					hash = hash.replace(location.protocol + '//' + location.host, '');
					hash = hash.replace(/^.*#/, '');
					$.historyLoad(hash);
					return false;
				});

				$("#tags").tagcloud( {
					type : "sphere",
					height : 305,
					sizemin : 11,
					sizemax : 30,
					power : .3
				});
			});
		});

		$("a[rel='ajax']").click( function() {
			var hash = this.href;
			hash = hash.replace(/%20/gi, '+');
			hash = hash.replace(location.protocol + '//' + location.host, '');
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});

		$("#tags").tagcloud( {
			type : "sphere",
			height : 305,
			sizemin : 11,
			sizemax : 30,
			power : .3
		});
	},

	
	searchInit : function() {
		$.historyInit(function(hash) {
			if (hash) {
				$("#load").load($.rtl.encode(hash), {}, function() {
					$("a[rel='ajax']").click(function() {
						var hash = this.href;
						hash = hash.replace(/%20/gi, '+');
						hash = hash.replace(/^.*#/, '');
						hash = hash.replace(location.protocol + '//' + location.host, '');
						$.historyLoad(hash);
						return false;
					});
				});
			} else {
				$("#load").empty();
			}
		});

		$("a[rel='ajax']").click( function() {
			var hash = this.href;
			hash = hash.replace(/%20/gi, '+');
			hash = hash.replace(/^.*#/, '');
			hash = hash.replace(location.protocol + '//' + location.host, '');
			$.historyLoad(hash);
			return false;
		});
	},
	
	portfolioInit : function(config) {	
		$.historyInit( function(hash) {
			if (hash) {				
				$.getJSON($.rtl.encode(hash), function(data) {
					$("#title").html(data['title']);
					el = $("#left");
					el.css('width', el.parent().css('width'));
					el.animate( {
						left : el.parent().css('width')
					}, 400, function() {
						el.hide();
						el.html(data['left']);
						el.css('left', '-' + el.parent().css('width'));
						el.show();
						el.animate( {
							left : '0px'
						}, 400);
						$("a[rel='ajax-portfolio']").click( function() {
							var hash = this.href;
							hash = hash.replace(/%20/gi, '+');
							hash = hash.replace(location.protocol + '//' + location.host, '');
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});
					});
					el2 = $("#right");
					el2.css('width', el2.parent().css('width'));
					el2.animate( {
						left : '-' + el2.parent().css('width')
					}, 400, function() {
						el2.hide();
						el2.html(data['right']);
						el2.css('left', el2.parent().css('width'));
						el2.show();
						el2.animate( {
							left : '0px'
						}, 400);

						$('a.lightBox').lightBox(config);

						$("a[rel='ajax-portfolio']").dblclick(function() {
							var hash = this.href;
							hash = hash.replace(/%20/gi, '+');
							hash = hash.replace(location.protocol + '//' + location.host, '');
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});					
						
						$("a[rel='ajax-portfolio']").click(function() {
							var hash = this.href;
							hash = hash.replace(/%20/gi, '+');
							hash = hash.replace(location.protocol + '//' + location.host, '');
							hash = hash.replace(/^.*#/, '');
							$.historyLoad(hash);
							return false;
						});
					});
				});
			}
		});

		$('a.lightBox').lightBox(config);

		$("a[rel='portfolio']").dblclick( function() {
			var hash = this.href;
			hash = hash.replace(/%20/gi, '+');
			hash = hash.replace(location.protocol + '//' + location.host, '');
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});
		
		$("a[rel='portfolio']").click( function() {
			var hash = this.href;
			hash = hash.replace(/%20/gi, '+');
			hash = hash.replace(location.protocol + '//' + location.host, '');
			hash = hash.replace(/^.*#/, '');
			$.historyLoad(hash);
			return false;
		});

		var container = $('div.sliderGallery');
		var ul = $('ul', container);
		var itemsWidth = ul.innerWidth() - container.outerWidth();
		$('.slider', container).slider( {
			min : 0,
			max : itemsWidth,
			handle : '.handle',
			stop : function(event, ui) {
				ul.animate( {
					'left' : ui.value * -1
				}, 500);
			},
			slide : function(event, ui) {
				ul.css('left', ui.value * -1);
			}
		});
	}
};