
var Site = {
	
	start: function(){
		
		Site.rollOver();
		if (window.gecko) Site.formLayoutFix();
		Site.tracker("UA-7963800-1");
		Site.ajaxWireUp();
		Site.fetchWireUp();
		if ($('feature')) {
			Site.video();
			//Site.videoWireUp();
		}
		Site.menuWireUp();
		//if ($('tabList')) Site.tabWireUp();	
		
	},
	
	menuWireUp:function() {
		$$('.toggle').each(function(el) {
		
			var myVerticalSlide = new Fx.Slide(el.id + 'Container');

			$(el.id).addEvent('click', function(e){
				e.stop();
				myVerticalSlide.toggle();
			});	
			
		});
		

	},
	
	
	tabWireUp:function() {	
		var myTabs = new MorphTabs('tabList',{changeTransition: {
    transition: 'linear',
    duration: 'short'
},
panelStartFx: 'fade',
panelEndFx: 'appear'
});
	},
	



		ajaxWireUp:function() {	
		$$('.ajax').each(function(el) {
			var id = el.id;
			var container = el.getParent('div.container');
			if (container) {
				var options = el.className.match(/ajax \[(.*)\] (\S+)/);
				el.addEvent(options[1], function(e) {
				e = new Event(e).stop();
				var request = new Request.HTML({
					url:options[2],
					update: container,
					onSuccess :  function() { Site.ajaxWireUp();  Site.rollOver(); }
					}).post(container);
				});
			}
		});
	},
	
		videoWireUp:function() {	
		$$('.video-link').each(function(el) {
				var options = el.className.match(/video-link (\S+)/);
				el.addEvent('click', function(e) {
				e = new Event(e).stop();
				//alert('click');
				$('ssp').sspLoadContent(options[1]);
				});
			});
	},
	
	
	
	

	
		video: function() {
		
		var obj = new Swiff('/assets/swf/video.swf', {
		container: 'feature',
		id:'ssp',
		width: 504,
		height: 281,
		params: {
		    wmode: 'transparent',
		    base: ".",
			quality: "best",
			bgcolor: "#333639",
			allowfullscreen: "true",
			allowScriptAccess: "always"
		    },
		vars: {
			xmlfiletype: "Director",
			xmlfile: "http://www.stylepalace.com.au/admin/ssp_director/images.php?album=7",
			initialURL: escape(document.location),
			useExternalInterface: "true",
						expressinstall : "/assets/swf/expressInstall.swf",
			version : "10"
		}
		});
		$$('.video-link').each(function(el) {
				var options = el.className.match(/video-link (\S+)/);
				el.addEvent('click', function(e) {
				e = new Event(e).stop();
				$('ssp').sspLoadContent(options[1]);
				});
			});	

	},
	

	
		album: function(album) {
		var obj = new Swiff('/assets/swf/sp_gallery.swf', {
container: 'album',
    width: 960,
    height: 600,
    params: {
        wmode: 'transparent',
        base: ".",
	quality: "best",
	allowfullscreen: "false"
    },
    vars: {
	xmlfiletype: "Director",
	xmlfile: "http://www.stylepalace.com.au/admin/ssp_director/images.php?album=" + album,
	initialURL: escape(document.location)
    }
});
		
   
},
	
	
		fetchWireUp:function() {	
		$$('.fetch').each(function(el) {
				var options = el.className.match(/fetch \[(.*)\] (\S+)/);
				el.addEvent('click', function(e) {
				e = new Event(e).stop();	
				var request = new Request.HTML({
					url:options[2],
					update: options[1],
					onSuccess :  function() { Site.ajaxWireUp(); 	  }
					}).get();
				});
		});
	},
	


	sfHover: function(){
		$$("#nav li").addEvents({
			'mouseover' : function() { this.addClass("sfhover"); },
			'mouseout' : function() { this.removeClass("sfhover"); }
		});
	},
	
	smoothScroller : function() {
		new SmoothScroll();
	},
	
	tracker: function(code) {
		new Asset.javascript('https://ssl.google-analytics.com/ga.js', {
			id: 'gaTracker',
			onload: function() {
				var pageTracker = _gat._getTracker(code);
				pageTracker._initData();
				pageTracker._trackPageview();	
			}
		});
	},

fader : function() {
$$('.fader').each(function(el, i) {
	var ExampleFx = new Fx.Style(el, 'opacity', { 
	wait: false,
	duration: 400,
	transition: Fx.Transitions.Quart.easeInOut});
		el.addEvent('mouseenter', function() { ExampleFx.start(1, 0.01); });
		el.addEvent('mouseleave', function() { ExampleFx.start(0.01, 1); });
});
},



menu: function(){
	
		//create our Accordion instance
	var myAccordion = new Accordion($('accordion'), 'span.cat', 'div.element', {
		opacity: false,
		start: 'all-closed',
		onActive: function(toggler, element){
			
		},
		onBackground: function(toggler, element){
			
		}
	});
	
	
},


	


 



	rollOver : function() {
		$$("img").each( function(el) {
			if (el.hasClass("rollover")) {
			el.setAttribute("xsrc",el.getAttribute("src"));
			el.addEvents({
				'mouseover' : function() { this.setAttribute('src',this.className.match(/rollover (\S+)/)[1]); },
				'mouseout' : function() { this.setAttribute('src',this.getAttribute("xsrc")); }
			});
			}
		});
	},	

	

	formLayoutFix : function() {
	$$('.form label').each( function(el) {
		var content = el.getText();
		el.empty();
		el.adopt(new Element('span', {
			'styles' : {
				'display' : 'block',
				'width' : el.getStyle('width')
			}		
		}).setText(content));
		el.setStyle('display','-moz-inline-box');
		});	
	}



	
}


window.addEvent('domready', function() {Site.start()});







