// common js


function initSqueezebox()
{
	/**
     * Set default options, overrideable from later calls.
     */
    SqueezeBox.initialize({
        size: {x: 350, y: 400}
    });
 
    /**
     * Assign SqueezeBox to all links with rel="boxed" attribute, the class then reads the "href".
     */
    SqueezeBox.assign($$('a[rel=boxed]'));
 
    

}

function initTnGallery(){
		
	if($('tngallery'))
	{
		var cs = new ContentSlider({
			increment:85,
			container:$('tngallery_list'),
			slidingEl: "#tngallery_list li",
			next_btn:$('tngallery_next'),
			previous_btn:$('tngallery_back')
		});
	}
}

function setPageValidator()
{
	var vlink = $('validatorLink');
	if(!vlink) return;
	
	vlink.set('href', 'http://validator.w3.org/check?uri='+window.location );
}

// utilities
var ssUtil = {
	
	$get:function(key,url){
		/*
			util for reading get vars
		key - string; optional; param key to search for
		url - string; optional; the url to check for "key" in
		
		Example: 
		>$get("foo","http://example.com/?foo=bar"); //returns "bar" 
		>$get("foo"); //returns the value of the "foo" variable if it's present in the current url(location.href) 
		>$get("#","http://example.com/#moo"); //returns "moo" 
		>$get("#"); //returns the element anchor if any, but from the current url (location.href) 
		>$get(,"http://example.com/?foo=bar&bar=foo"); //returns {foo:'bar',bar:'foo'} 
		>$get(,"http://example.com/?foo=bar&bar=foo#moo"); //returns {foo:'bar',bar:'foo',hash:'moo'} 
		>$get(); //returns same as above, but from the current url (location.href) 
		>$get("?"); //returns the query string (without ? and element anchor) from the current url (location.href) 
	 
		Returns: 
			Returns the value of the variable form the provided key, or an object with the current GET variables plus the element anchor (if any) 
			Returns "" if the variable is not present in the given query string
		*/
		
		if( arguments.length < 2 ) url = location.href;
		if( arguments.length > 0 && key != ''){
			// key
			if( key == '#' ){
				var regex = new RegExp('[#]([^$]*)');
			} else if(key == '?'){
				var regex = new RegExp('[?]([^#$]*)');
			} else {
				var regex = new RegExp('[?&]' + key + '=([^&#]*)');
			}
			
			var results = regex.exec(url);
			return (results == null ) ? '' : results[1];
			
		} else {
			// no key
			url = url.split('?');
			var results = {};
			if( url.length > 1 ){
				url = url[1].split('#');
				if( url.length > 1 ) results["hash"] = url[1];
				url[0].split('&').each(function(item,index){
					item = item.split('=');
					results[item[0]] = item[1];
				});
				
				return results;
			}
			
		}
	}
	
}


	


/////////////////////////////////////////
/////////////////////////////////////////
window.addEvent('domready', initTnGallery);
window.addEvent('domready', setPageValidator);



