/**
 * Rewrites language switching links to be page relative
 */
$(function () {
    $('p.lang a').each(function () {
        var lang = $(this).attr('href');
        var url = lang + location.pathname.substring(4);
        $(this).attr('href', url);
    });
});



// {{{ SlideShowPro

var lastGalleryId = 0;

/**
 * SSP: Embeds specified gallery
 */
function embedGallery(album, vars, id) {
    var flashvars = {
        paramXMLPath: "/galleries/param.xml",
        initialURL: escape(document.location),
        xmlFilePath: "/galleries/images.php"
    }
    var params = { 
        base: ".",
        quality: "best",
        bgcolor: "#121212",
        allowfullscreen: "true",
        wmode: "transparent"
    }
    
    lastGalleryId++;
    var movieId = 'ssp'+lastGalleryId; 
    
    if (album) {
    	flashvars['xmlFilePath'] += '?album='+album;
    }
    
    var width = 985;
    var hieght = 289;
    if (vars) {
        for(v in vars) {
            flashvars[v] = vars[v];
        }
        if (vars['width']) {
        	width = vars['width'];
        }
        if (vars['height']) {
        	width = vars['height'];
        }
    }
    
    if (!id) {
        id = 'flashcontent';
    }
    
    swfobject.embedSWF(
        "/galleries/slideshowpro.swf", 
        id, 
        "985", 
        "289", 
        "9.0.0", 
        false, 
        flashvars, 
        params, 
        {id: movieId} 
    );
}

/**
 * SSP: Specific handlers
 */
function flashPutHref(href) {
    location.href = href;
}
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
	    return document[movieName]
	}
}

// }}} SlideShowPro

// {{{ Products Carousel

var lang = location.pathname.substring(0, 3);
var sliders = new Object;
sliders['acoustics'] = ['.list', lang+'/products/acoustics/'];
sliders['usbl'] = ['.list', lang+'/products/USBL/'];

function initCarousel(id) {
    var slider = sliders[id];
    if (slider === undefined) {
        alert('Unknown slider "'+id+'"!');
        return;
    }
    
    var start_index = 1*$.cookie('carousel-'+id);
    if (!start_index) {
        start_index = 0;
    }

    $(slider[0]).jCarouselLite({
        btnNext: "a.next",
        btnPrev: "a.prev",
        afterEnd: function (item) {saveCarousel(id, item);},
        start: start_index
    });
}
/**
 * Save position in carousel
 */
function saveCarousel(id, current) {
    var slider = sliders[id];
    $(slider[0]+' li').each(function (i) {
        var img1 = $(current[0]).find('img').attr('src');
        var img2 = $(this).find('img').attr('src');
        if (img1 == img2) {
            $.cookie('carousel-'+id, i, { path: slider[1] });
        }
    });
}

// }}} Products Carousel
// {{{ Menu fix for Linux

$(function () {

});
// }}} Menu fix for Linux
