var totalImages = new Array();
var totalImagesCount = 0;
var curImage = 0;
var cur = 0;
var stile = 0;
var lang = 'en'
function startSlideShow(cName){
    jumpImage(curImage + 1);
    $j.timer(3000, function(timer){
        jumpImage(curImage + 1);
        $j('#ssStop').click(function(e){
            timer.stop();
            $j('#ss').html('<a href="javascript:startSlideShow(\'img.ih\')">start slideshow</a>');
            $j("#mp").remove();
        });
    });
    
    $j('#ss').html('<a href="#" id="ssStop" onclick="return false;">stop slideshow</a>');
    $j("#footer").append('		<object width="0" height="0" id="mp"><param name="src" value="/i/w.mp3"><param name="autoplay" value="true"><param name="controller" value="false"><param name="bgcolor" value="#FFFFFF"><embed src="/i/w.mp3" autostart="true" loop="true" width="0" height="0" controller="false" bgcolor="#FFFFFF"></embed></object>');
}

function initImages(obj, ord, total){
    capstanga = 0;
    capdreapta = 4;
    $j(obj).css("display", "none");
    $j(obj).css("visibility", "visible");
    totalImages[ord] = obj;
    totalImagesCount++;
    if ($j('#tImg')) 
        $j('#tImg').text(totalImagesCount);
    if (ord == (total - 1)) {
        $j.timer(1500, function(timer){
            $j('#right').css('background', 'none')
            $j(totalImages[0]).fadeIn("normal");
            curImage = 0;
            if ($j('#cImg')) 
                $j('#cImg').text(curImage + 1);
            timer.stop();
        });
    }
}

function showNextImg(){
    $j(totalImages[curImage]).fadeOut(300);
    curImage++;
    if (curImage > totalImagesCount - 1) 
        curImage = 0;
    $j(totalImages[curImage]).fadeIn(300);
    $j('#cImg').text(curImage + 1);
}

function showPrevImg(){
    $j(totalImages[curImage]).fadeOut(300);
    curImage--;
    if (curImage < 0) 
        curImage = totalImagesCount - 1;
    $j(totalImages[curImage]).fadeIn(300);
    $j('#cImg').text(curImage + 1);
}

function jumpImage(x){
    var v = 0;
    if (x <= totalImagesCount - 1) {
        $j("#" + "p" + curImage + ".image_lite").css("background-color", "");
        $j("#" + "p" + x + ".image_lite").css("background-color", "#CCCCCC");
        $j(totalImages[curImage]).fadeOut(300);
        curImage = x;
        $j(totalImages[curImage]).fadeIn(300);
        $j('#cImg').text(x + 1);
        p = 0;
        aux = 0;
        if (x == capdreapta) {
            p = 1;
            aux = totalImagesCount - x - 1;
            if (aux > 4) {
                aux = 4;
            }
            i = 0;
            while (i < aux) {
                $j("#" + "p" + (capstanga + i)).toggle("slow");
                i = i + 1;
            }
            i = 1;
            while (i <= aux) {
                $j("#" + "p" + (x + i)).toggle("slow");
                i = i + 1;
            }
        }
        if (x == capstanga) {
            p = 2;
            aux = x;
            if (aux > 4) {
                aux = 4;
            }
            i = 0;
            while ((i < aux)) {
                $j("#" + "p" + (capdreapta - i)).toggle("slow");
                i = i + 1;
            }
            i = 1;
            while (i <= aux) {
                $j("#" + "p" + (capstanga - i)).toggle("slow");
                i = i + 1;
            }
            aux = -aux;
        }
        
        capstanga = capstanga + aux;
        capdreapta = capdreapta + aux;
        
        if (totalImagesCount == x + 1) {
            $j('#nxt').html('>');
        }
        else {
            if ((p == 2) && (x != 0)) {
                $j('#nxt').html('<a href="javascript:jumpImage(' + (x) + ')"> > </a>');
            }
            else {
                $j('#nxt').html('<a href="javascript:jumpImage(' + (x + 1) + ')"> > </a>');
            }
            
        }
        if (x == 0) {
            $j('#prv').html('<');
        }
        else {
            if ((p == 1) && (x != totalImagesCount - 1)) {
                $j('#prv').html('<a href="javascript:jumpImage(' + (x) + ')"> < </a>');
            }
            else {
                $j('#prv').html('<a href="javascript:jumpImage(' + (x - 1) + ')"> < </a>');
            }
            
        }
    }
}



function toggleMenu(obj){
    $j('#' + obj).slideToggle("slow");
}

function $set(tip){
    if (tip == '0' || tip == '3') {
        $j('#info').hide('fast');
        $j('#foto').hide('fast');
    }
    
    
    
}

function LoadPhotos(page,name){
         new Ajax.Request('/ajax/'+page+'/'+name, { onSuccess: function(request) {
      $('right').update(request.responseText);
    }})

}


function showPage(option){
    //$j('#cImg').text(curImage+1);
	$j('#ss').html("<a href=\"javascript:startSlideShow('img.ih')\">start slideshow</a>");
    //if (option == 'slideshow') start_slideshow();
    //if (option == 'price_list') $j("#price_list").css("display", "block");
}


function switch_style(css_title){
    // You may use this script on your site free of charge provided
    // you do not remote this notice or the URL below. Script from
    // http://www.thesitewizard.com/javascripts/change-style-sheets.shtml
    var i, link_tag;
    for (i = 0, link_tag = document.getElementsByTagName("link"); i < link_tag.length; i++) {
        if ((link_tag[i].rel.indexOf("stylesheet") != -1) &&
        link_tag[i].title) {
            link_tag[i].disabled = true;
            if (link_tag[i].title == css_title) {
                link_tag[i].disabled = false;
            }
        }
        Set_Cookie('st', css_title, '', '/', '', '');
    }
    a = 'black'
    b = 'white'
    if (css_title == 'white') {
        document.getElementById('style').innerHTML = '<a href="JavaScript:switch_style(a)"></a>';
    }
    else {
        document.getElementById('style').innerHTML = '<a href="JavaScript:switch_style(b)"></a>';
    }
}





function Set_Cookie(name, value, expires, path, domain, secure){
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());
    
    /*
     if the expires variable is set, make the correct
     expires time, the current script below will set
     it for x number of days, to make it for hours,
     delete * 24, for minutes, delete * 60 * 24
     */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));
    
    document.cookie = name + "=" + escape(value) +
    ((expires) ? ";expires=" + expires_date.toGMTString() : "") +
    ((path) ? ";path=" + path : "") +
    ((domain) ? ";domain=" + domain : "") +
    ((secure) ? ";secure" : "");
}

function Get_Cookie(check_name){
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f
    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');
        
        
        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
        
        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}











