$(function(){
    // Collapse
    
    $('div#content h1').html('Desenhos');
    
   
    urlPlace = window.location;
    if( urlPlace == "http://www.wellington.art.br/desenhos.html" || urlPlace == "http://wellington.art.br/desenhos.html"){
        urlPlace = "alien";
    }else{
        urlPlace = urlPlace.toString().replace('http://www.wellington.art.br/desenhos/','').replace('.html','');
    }

    $('div#jobLeft dl dd').hide();
    
    img = { imgName : urlPlace, imgTitle : "Alien" };

    if(urlPlace){
        img.imgTitle = img.imgName;
    }else{
        img.imgName = 'alien';
        img.imgTitle = 'Alien';
        $('div#jobLeft dl dt a').eq(0).addClass('open').css('color','red');$('div#jobLeft dl dd a').eq(0).css('color','red');
        $('div#jobLeft dl').eq(0).find('dd').show();
    }
    
    $('div#jobLeft dl dt a').click(function(e){
        e.preventDefault(); e.stopPropagation();
        
        $('div#jobLeft dl dd').hide(); $('div#jobLeft dl dt a').addClass('close').removeClass('open');
        
        if( $(this).attr('class') == "close" ){
            $(this).addClass('open').removeClass('close');
            $(this).parents('dl').find('dd').show();
        }else if( $(this).attr('class') == "open" ){
            $(this).addClass('close').removeClass('open');
            $(this).parents('dl').find('dd').hide();
        }
    })
    
    
    $.ajax({
        type: "GET",
        url: "desenhos.html",
        data: "img=true&imgName=" + urlPlace + "&imgTitle=" + img.imgTitle,
        success: function(msg){
            $('div#jobRight').html(msg);
            $('div#imgThumbs a').click(function(e){
                e.preventDefault(); e.stopPropagation();
                    imgUrl = $(this).attr('href').replace('http://www.wellington.art.br/desenhos/','').replace('.html','');
                    texto = $(this).text();
                    imgName = imgUrl;
                $('div#imgMaster').html('<p id="loadAllBig">Carregando...</p>');
                $.ajax({
                    type: "GET",
                    url: "desenhos.html",
                    data: "imgBig=true&imgUrl=" + imgUrl + "&imgTitle=" + texto,
                    success: function(msg){
                        $('div#imgMaster').html(msg);
                    }
                });
            })
        }
    });

    $('div#jobLeft dl dd a').click(function(e){
        e.preventDefault(); e.stopPropagation();
        $('div#jobLeft dl dd a,div#jobLeft dl dt a').css('color','');

        $(this).parents('dl').find('dt a').css('color','red');
        $(this).css('color','red');

        imgUrl = $(this).attr('href').replace('http://www.wellington.art.br/desenhos/','').replace('.html','');
        texto = $(this).text();

        imgName = imgUrl;
        
        $('div#jobRight').html('<p id="loadAll">Carregando...</p>');
		$('div#content h1').html('Desenhos - ' + texto);
        $.ajax({
            type: "GET",
            url: "desenhos.html",
            data: "img=true&imgName=" + imgName + "&imgTitle=" + texto,
            success: function(msg){
                $('div#jobRight').html(msg);
                $('div#imgThumbs a').click(function(e){
                    e.preventDefault(); e.stopPropagation();
                    imgUrl = $(this).attr('href').replace('http://www.wellington.art.br/desenhos/','').replace('.html','');
                    texto = $(this).text();
                    imgName = imgUrl;
                    $('div#imgMaster').html('<p id="loadAllBig">Carregando...</p>');
                    $.ajax({
                        type: "GET",
                        url: "desenhos.html",
                        data: "imgBig=true&imgUrl=" + imgUrl + "&imgTitle=" + texto,
                        success: function(msg){
                            $('div#imgMaster').html(msg);
                        }
                    });
                })
            }
        })
    })
    
})
