cart_window_width  = 300;
cart_window_height = 150;
	
	
//
// Init popup windows for images
//
function popups_init()
{
    var ancs = document.getElementsByTagName("a");
    for (i=0; i<ancs.length; i++) {
        if ((ancs.item(i).className).indexOf("popup")!=-1) {
            // popup-width-height
            parts = ancs.item(i).className.split("-");
            addEvent(ancs.item(i), 'click', create_show_image_func(ancs.item(i).href, parts[1], parts[2]), false);
        }
        else if ((ancs.item(i).className).indexOf("order")!=-1) {
            // add-to-cart window
            addEvent(ancs.item(i), 'click', create_show_cart_func(ancs.item(i).href), false);
        }
    }
}

function create_show_cart_func(href)
{
    return function(e) { 
        if (e.preventDefault) {
            e.preventDefault();
        }
        show_cart(href);
        return false;
    };
}

function show_cart(href)
{
	var width  = cart_window_width;
	var height = cart_window_height;
	
    var left = (screen.width-width)/2;
    var top  = (screen.height-height)/2;

    features = 'width='+width+', height='+height+', location=no, menubar=no, personalbar=no, resizable=yes, scrollbars=no, status=no, titlebar=yes, toolbar=no, left='+left+', top='+top;
	var w = window.open(href, 'cartwind', features);
	w.focus();
	
    return false;
}

function create_show_image_func(href, width, height)
{
    return function(e) { 
        if (e.preventDefault) {
            e.preventDefault();
        }
        show_image(href, width, height); 
        return false;
    };
}

function show_image(href, width, height)
{
        var left = (screen.width-width)/2;
        var top  = (screen.height-height)/2;
        
        height = 30 + parseInt(height);
        features = 'width='+width+', height='+height+', location=no, menubar=no, personalbar=no, resizable=yes, scrollbars=no, status=no, titlebar=yes, toolbar=no, left='+left+', top='+top;
		openedWindow = window.open('/pic.php?p='+href+'&w='+width+'&h='+height, 'mywind', features);
		openedWindow.focus();
        return false;
}



//
// Style switcher
//
function init_style()
{
    // read cookie
    style_name = readCookie('setstyle');
    
    // anime is default style
    style_name = (style_name)?style_name:'anime'
    
    // set class name for BODY
    document.getElementsByTagName("body").item(0).className=style_name;
}

function set_style(style_name)
{
    // set class name for BODY
	document.getElementsByTagName("body").item(0).className=style_name;
	
	// set cookie
	createCookie('setstyle', style_name, 365)
	return false;
}

