var scrollableApi;

function setSectionLink(){
    $(".section").click(function() {
        window.location.href=$(this).find("a.overlay")[0];
    });
}

function openAsPopUp(){
    $(".openAsPopUp").click(function() {
        var strWidth = 'width=' + getClassParameter(this, 'width', '');
        var strHeight = ',height=' + getClassParameter(this, 'height', '');
        var strToolbars = ',toolbar=' + getClassParameter(this, 'toolbar', 'no');
        var strScrolling = ',scrollbars=' + getClassParameter(this, 'scrollbars', 'no');
        var strStatus = ',status=' + getClassParameter(this, 'status', 'no');
        var strResize = ',resizable=' + getClassParameter(this, 'resizable', 'yes');
        var strLocation = ',location=' + getClassParameter(this, 'location', 'no');
        var strMenu = ',menu=' + getClassParameter(this, 'menu', 'no');
        var strName = getClassParameter(this, 'name', 'popup');
        window.open(this.getAttribute('href'), strName, strWidth+strHeight+strScrolling+strToolbars+strStatus+strResize+strLocation+strMenu);
        return false;
    });
}

function openAsNewWindow(){
    $(".extern").click(function() {
        window.open(this.getAttribute('href'));
        return false;
    });
}

// returns a string of parameters found in the classname which can be [eval]uated
function getClassParameter(targetNode, paramName, defaultValue){
    // get the class parameter from the classname
    var classParameter = targetNode.className;
    // split the classname between the parameter name
    classParameter = classParameter.split(paramName + '_');
    // split the second piece between spaces and take the first part,  if there are two pieces
    classParameter = (classParameter.length>1) ? classParameter[1].split(' ')[0] : null ;
    // return the value
    return (classParameter!=null) ? classParameter : defaultValue ;
}

function togglePlay () {
	$("#pushbox .pause").click(function() {
		scrollableApi.stop();
		$(this).removeClass("pause").addClass("play");
		togglePlay();
	});
	$("#pushbox .play").click(function() {
		scrollableApi.play();
		$(this).removeClass("play").addClass("pause");
		togglePlay();
	});
}

jQuery(function($) {
	setSectionLink();
	if($("#pushbox .item").length > 1){
		var root = $("#pushbox").scrollable({circular: true}).autoscroll({autoplay: false, autopause:false, interval:5000}).navigator({
		navi:'div.navi ul'
		});
		scrollableApi = root.data("scrollable");
		scrollableApi.play();
		togglePlay();
	}
	openAsPopUp();
        openAsNewWindow()
});


