$(document).ready(function(){

	$.address.change(function(event) {

		// Split string to get file name and vars
		event.value = event.value.split("/")  
		
		// If not set show home page
		if(event.value[1] == ""){
			event.value[1] = "home";
		}

		// Build file name string
		var content_page = base_url+"public/content/"+event.value[1]+".inc.php";

		// Loop through extra params and add to file name string
		for (var i = 2; i < event.value.length; i++) {
			if ( event.value[i] != "" && i == 2 ) {
				content_page = content_page + "?var" + i + "=" + event.value[i];
			} else if ( event.value[i] != "" ) {
				content_page = content_page + "&var" + i + "=" + event.value[i];
			}
		}

		// Load content into content panel
		load_content(content_page, event.value[1]);
			
	});  
	
	$('a').click(function() {  
		$.address.value($(this).attr('href'));  
	});

	// If non dealer site show flash with dealer links
	if ($("#flash").length > 0){
		var so = new SWFObject(base_url+"/flash/kemble_top_"+language+".swf", "kembele_top", "949", "335", "8", "#000000");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("flash");
	}
	
	// If dealer site show flash header without dealer locator
	if ($("#dealerflash").length > 0){
		var so = new SWFObject(base_url+"/flash/kemble_dealer_top_"+language+".swf", "kembele_dealer", "949", "335", "8", "#000000");
		so.addParam("quality", "high");
		so.addParam("wmode", "transparent");
		so.write("dealerflash");
	}
	
	var so = new SWFObject(base_url+"flash/footer_"+language+".swf", "footer", "949", "115", "8", "#000000");
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.addVariable("language_id", language);
	so.write("footer");	

	//display_video('kemble_vid.flv');

});

function openNewWindow(URLtoOpen, windowName, windowFeatures,windowWidth,windowHeight) {
newWindow=window.open(URLtoOpen, windowName, windowFeatures);
winLeft = (screen.width/2) - (windowWidth/2);
winTop = (screen.height/2) - (windowHeight/2);
newWindow.moveTo(winLeft,winTop);
newWindow.focus();
} 

function load_content(content_page, title){

	$.ajax({
	  url: content_page,
	  async: false,
	  dataType: "html",
	  success: function(html){
	  	display_content(html, title);
	  },
	  error:  function(html){
		load_content(base_url+"content/404.inc.php", 'error404');
	  }
	
	 }).responseText;		
}

function display_content(html, title) {

		$("#content").fadeOut('fast', function(){ 
		$("#wrapper").removeClass();
		$("#wrapper").addClass(language).addClass(title);
	
		$("body").removeClass();
		$("body").addClass("body_"+title);
	
		$("#content").html(html);

		$("#content").fadeIn('fast', function(){	
			
			$('.scrolling').jScrollPane({showArrows: true, scrollbarMargin: 10, scrollbarWidth: 15, arrowSize: 15});

			Shadowbox.setup("a[rel=shadowbox]", {
		        autoplayMovies:     true,
		        height:     556,
		        width:      700
		    });
		    
			Shadowbox.setup("a[rel=shadowbox100years]", {
		        autoplayMovies:     true
		    });		    
		
			Shadowbox.setup("a[rel=shadowbox512x288]", {
		        autoplayMovies:     true,
		        height:     288,
		        width:      512
		    });
		
		});
	});	
}

function display_video(sFilename){

	var so = new SWFObject(base_url+"/flash/player.swf", "kembele_top", "949", "335", "8", "#000000");
	so.addVariable('file',base_url + '/flash/kemble_vid.flv');
	so.addParam("quality", "high");
	so.addParam("wmode", "transparent");
	so.write("video");

}

function display_swf(sFilename){
	
	var v = new SWFObject(site_url + 'flash/'+sFilename+'.swf','vid',320,180,'8');

    v.write('video');
}
