var stack = [];
var loaded=false;
var onc=false;
function ll() {
    var div = document.createElement('div'),
        ref = document.getElementsByTagName('base')[0] ||
              document.getElementsByTagName('script')[0];
    div.innerHTML = '&shy;<style> iframe { visibility: hidden; } </style>';
    ref.parentNode.insertBefore(div, ref);
return div;
}

function makeScrollable(wrapper, scrollable) {
    var wrapper = $(wrapper),
        scrollable = $(scrollable);
    if (!loaded && !onc) {
onc=true;
        $.ajax({
                type: "GET",
                url: "gallery/gallery.xml",
                dataType: "xml",
                cache: false,
                success: function (xml) {
                    var j = 1;
                    $(xml).find('image').each(function () {
                        var img = $(this).find('filename').text();
                        var capt = $(this).find('caption').text();
                        $('<a href="#" id="' + (j++) + '"></a>').html('<img src="' + img + '" /><div class="det">' + capt + '</div><div class="brd"></div>').appendTo('.sc_menu');
                    });
                }
            });$.ajax({
                type: "GET",
                url: "gallery/slides.xml",
                cache: false,
                dataType: "xml",
                success: function (xml) {
                    var i = 0;
                    $(xml).find('image').each(function () {
                        var img = $(this).find('filename').text();
                        var capt = $(this).find('caption').text();
                        $('<div></div>').html('<img src="' + img + '" width="720" height="540" /><div class="det">' + capt + '</div>').appendTo('#slideshow');
                    });
   $('#slideshow').cycle({
            timeout: 2000
        });
                }
            });
        var interval = setInterval(function () {
            var images = scrollable.find('img');
            var completed = 0;
            images.each(function () {
                if (this.complete) completed++;
            });
            if (completed >= 3) {
                clearInterval(interval);
                setTimeout(function () {
                    wrapper.css({
                        overflow: 'hidden'
                    });   loaded = true;
                        enable();
                    
                }, 100);
            }
        }, 100);
    }
 else
enable();

    function enable() {
        var inactiveMargin = 99;
        var wrapperWidth = wrapper.width();
        var wrapperHeight = wrapper.height();
        var scrollableHeight = scrollable.outerHeight() + 2 * inactiveMargin;
        var lastTarget;          
wrapper.unbind('mousemove');
        wrapper.mousemove(function (e) {
            lastTarget = e.target;
            var wrapperOffset = wrapper.offset();
            var top = (e.pageY - wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
            if (top < 0) {
                top = 0;
            }
            wrapper.scrollTop(top);
        });
        $('#up').unbind("click");
        $('#up').click(function () {
            if (wrapper.scrollTop() > wrapper.offset().top) wrapper.animate({
                scrollTop: (((wrapper.scrollTop() - 522) > 0) ? (wrapper.scrollTop() - 522) : 0)
            }, 'slow', function () {
                wrapper.stop();
            });
        });
        $('#down').unbind("click");
        $('#down').click(function () {
            if (wrapper.scrollTop != scrollableHeight) wrapper.animate({
                scrollTop: (((wrapper.scrollTop() + 522) < ($(".sc_menu").attr("scrollHeight"))) ? (wrapper.scrollTop() + 522) : ($(".sc_menu").attr("scrollHeight")))
            }, 'slow', function () {
                wrapper.stop();
            });
        });
        $('#up').unbind("mouseover");
        $('#up').mouseover(function () {
            if (wrapper.scrollTop() > wrapper.offset().top) wrapper.animate({
                scrollTop: $(".sc_menu").offset().top
            }, 'slow', function () {
                wrapper.stop();
            });
        });
        $('#down').unbind("mouseover");
        $('#down').mouseover(function () {
            if (wrapper.scrollTop != scrollableHeight) wrapper.animate({
                scrollTop: $(".sc_menu").attr("scrollHeight")
            }, 'slow', function () {
                wrapper.stop();
            });
        });
        $('.sc_menu a').unbind("mouseover");
        $('.sc_menu a').mouseover(function () {
            $(this).stop(true, false).animate({
                opacity: 1
            }, 300);
            $(this).find('.det').stop(true, true).slideDown(300);
            $(this).find('.brd').stop(true, false).animate({
                width: '329px'
            }, 300);
        });
        $('.sc_menu a').unbind("mouseleave");
        $('.sc_menu a').mouseleave(function () {
            $(this).stop(true, false).animate({
                opacity: 0.5
            }, 300);
            $(this).find('.det').stop(true, true).slideUp(300);
            $(this).find('.brd').stop(true, true).animate({
                width: '0px'
            }, 300);
        });
        $('#slideshow div').unbind("mouseover");
        $('#slideshow div').mouseover(function () {
            $(this).find('.det').stop(true, true).slideDown(300);
        });
        $('#slideshow div').unbind("mouseleave");
        $('#slideshow div').mouseleave(function () {
            $(this).find('.det').stop(true, true).slideUp(300);
        });
        $('.sc_menu a').unbind("click");
        $('.sc_menu a').click(function () {
            var j = $(this).attr('id');
            $.ajax({
                type: "GET",
                url: "gallery/gallery.xml",
                cache: true,
                dataType: "xml",
                success: function (xml) {
                    var project = $('image:eq(' + (j - 1) + ')', $(xml));
                    var str = $('video', project).text();
                    str = str.replace('\&amp;quot;', '"');
                    var text = $('<div></div>').html('<div id="vid">' + str.replace(/\\"/g, '"') + '</div>');
                    $('#slideshow').hide();
                    $('#ddd').html($(text).text().replace(/\\"/g, '"'));
$('#ddd').hide();
var loading = $('<div class="loading" style="z-index:100; position:relative"><img src="img/pre.gif" width="183" height="2" /></div>').appendTo($('#dd'));
$('#ddd iframe').load(function(){ $('#ddd').show(); $(loading).remove();});
                }
            });
        });
    }
}
function onBefore(curr, next, opts) {
                                if (opts.addSlide) // <-- important! 
                                while (stack.length)
                                opts.addSlide(stack.pop());
                            };
function scro() {
    var inactiveMargin = 99;
    var wrapperWidth = wrapper.width();
    var wrapperHeight = wrapper.height();
    var scrollableHeight = scrollable.outerHeight() + 2 * inactiveMargin;
}
     function validate(){
    document.getElementById('type_msg').style.display='none';
    document.getElementById('type_name').style.display='none';
    document.getElementById('valid_email').style.display='none';
document.getElementById('sent_email').style.display='none';

if(document.contact.name.value == "" ) 
{
    document.getElementById('type_name').style.display='block';
 document.contact.name.focus();
 return false;
}

        
var x=document.contact.email.value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
      document.getElementById('type_name').style.display='none';
    document.getElementById('valid_email').style.display='block';  
  //alert("Not a valid e-mail address");
  document.contact.email.focus();
  return false;
  }
if(document.contact.massage.value == "" ) 
{
    //alert('hi');
    document.getElementById('type_msg').style.display='block';

//alert("Please Enter your Name")
 document.contact.massage.focus();
 return false;
}

$.post('contact_carlos.php',{  'userName':$('#name').val(),'userEmail':$('#email').val(),'userMsg':$('#massage').val()},function(){
        document.getElementById('sent_email').style.display='block';
$('#name').val('');
$('#email').val('');
$('#massage').val('');
return false;
       });
return false;
     }
//jQuery.noConflict();

function animate()
{
$('#send').css({'textAlign':'right'}); 
$('#send').css({'color':'#6FF'},"slow");
}

function no_animate()
{
$('#send').css({'textAlign':'left'}); 
$('#send').css({'color':'#FFF'},"slow");
}
function subm(){
    var rw='';
    $("label.checked").each(function(){
        if(!isNaN($(this).attr('for')))
            rw+=$(this).attr('for')+',';
        
    });
    $('#rws').val(rw);
    $('#feed').submit();
}
