$(document).ready(function() { 
    
    $(".expander").unbind("click");
	$(".expander").bind("click", function() {
		if ($(this).find("~ ul").is(":hidden")) $(this).text("-");
		else $(this).text("+");
		$(this).find("~ ul").slideToggle(200); 
		return false;
		});

    var options = { 
        target:        '#responseSign',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#singUpForm').ajaxForm(options);
    
    $('.bigLink:first').addClass('selectedThumb');
     
       
       
       $('.bigLink').bind('click',function(){
        
        if($(this).is('.selectedThumb')){
        return false;
        }
        
        $('.selectedThumb').removeClass('selectedThumb');
        
        var myString = new String($(this).attr('rel'));
        
        var paramsArr = myString.split(','); 
        
        //alert(paramsArr[0]);
        var imgURL = paramsArr[0];
        var imgHeight = paramsArr[4];
        var imgWidth = paramsArr[3];
        
        
        $(this).addClass('selectedThumb');
        showPic(imgURL,'','',imgWidth,imgHeight);
        
        //alert();
        
        });

    
}); 
 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
  //  alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
   // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
   //     '\n\nThe output div should have already been updated with the responseText.');
   
}


 
    
    function doAndShow(src){
        //doImage(img,url,width,height);
       $('#maxImage').remove();
       //alert(src);
       var img = new Image();
       $(img).load(function(){
        
        $(this).hide();
        
        $('.picturecontainer').append(this);
        
        $(this).fadeIn('slow');
        
        
        }).attr('src',src).attr('id','maxImage');
        // 
        // alert("aa");
        // jQuery('#maxImage').fadeIn('slow');
        // alert('a');
        //img.src=newImg.src;
         
    }
    
    
    function showPic(url,title,descr,width,height) {
       picSrc='assets/snippets/phpthumb/phpThumb.php?src='+url+'&w='+width+'&h='+height+'&zc=1&q=100';     
       $('#maxImage').fadeOut(500);
       setTimeout("doAndShow(picSrc)",600);
     
        //var img = document.getElementById('maxImage');
        
        
        //var newImg = new Image();
        //newImg.src='assets/snippets/phpthumb/phpThumb.php?src='+url+'&w='+width+'&h='+height+'&zc=1&q=100';
        
        //$(newImg).load();
        //$('#maxImage').fadeOut('slow',doAndShow(img,newImg));
        
               
        
       // newImg.onLoad = doAndShow(img,url,width,height);
        
        
        
        /*
       var img = document.getElementById('maxImage');
       var titleHolder = document.getElementById('maxTitle');
       var descrHolder = document.getElementById('maxDescr');
	   var newImg = new Image();
           
	   newImg.onLoad = doAndShow(img,url,width,height);
           
           
       if (titleHolder != null) {
               for (var i = 0; i < titleHolder.childNodes.length; i++) {
                       titleHolder.removeChild(titleHolder.childNodes[i]);
               };
               if (title != "") {
                       var node=document.createTextNode(title);
               }
               else {
                       var node=document.createTextNode("");
               }
               titleHolder.appendChild(node);
       }
       if (descrHolder != null) {
               for (var i = 0; i < descrHolder.childNodes.length; i++) {
                       descrHolder.removeChild(descrHolder.childNodes[i]);
               };
               if (descr != "") {
                       var node=document.createTextNode(descr);
               }
               else {
                       var node=document.createTextNode("");
               }
               descrHolder.appendChild(node);
       }
                              */
}
 
function doImage(img,url,width,height) {

img.src='assets/snippets/phpthumb/phpThumb.php?src='+url+'&w='+width+'&h='+height+'&zc=1&q=100';

}
    
