function setPlatform() {
    var userOSAgent = navigator.userAgent.toLowerCase();
    if (userOSAgent.match("windows")){

        if($.browser.mozilla ){        
            $("#navlist a").css("padding","7px 12px 12px");
            $("#navlist li").css("padding-top","1px");  
            $("#id_photo").css("width","230px");
        }
        else if ($.browser.msie && jQuery.browser.version.substr(0,3)=="8.0"){
             $(".madlibform textarea").css("height","60px");
             $(".profile_picture_small").css("padding-left", "6px");
             $(".profile_picture img").css("padding-left", "14px");
        }
        else if ($.browser.msie && jQuery.browser.version.substr(0,3)=="7.0") {   
            $("#id_photo").css("width","230px");
        }
        else if ($.browser.msie && jQuery.browser.version.substr(0,3)=="6.0") {
     
        }
        else if ($.browser.opera){
            $("ul#navlist").css("padding-top","6px");
            $("#navlist a").css("padding-top","6px");
            $("#id_photo").css("width", "230px");
            $("#story").css("height","60px");
            $("#story").css("width","38em");
        }
        else if (/chrome/.test( navigator.userAgent.toLowerCase() )){
            $("#id_photo").css("width","230px");   
        }
    }
    else if (userOSAgent.match("macintosh")){
        if($.browser.safari){
            $("#id_photo").css("width","230px");    
        }
         else if (/chrome/.test( navigator.userAgent.toLowerCase() )){
            $("#id_photo").css("width","230px");   
        }
    }

}

/*function signupFormDisable () {

    if ($("#registerbutton")){

        $("#registerbutton").attr("disabled", true );
        $("#registeragree").attr("value", 0 );
        
        
        $("#registeragree").click (function() {
        
            var b = $("#registerbutton").attr("disabled");
        
            $("#registerbutton").attr("disabled", !b);
        
        });
    }  
}*/


function setupLoginComponent() {
  
    var pw = $("#id_password")[0];
    var un = $("#id_username")[0];
    var search_field = $("#id_q")[0];
    
    $(un).val("");
    $(pw).val("");
    $(search_field).val("Search things, tales and groups");
    
    $(search_field).focus(function() {
       $(search_field).val("");
       
    });
    
    $(pw).focus(function() {
        $(pw).css("background-image","none");
    });
    
 
    $(un).focus(function() {
       $(un).val("");
       
    });
    
}

function transset() {

    $('#trans1').click(function() {
      $('#trans2').show();
      var step = $(document).width() / 5.0;
      $('#trans2').animate({
        left: '+=' +  ( $(document).width() + 390)
      }, 5000, function() {
        // Animation complete.
        $('#trans2').hide();
        $('#trans2').css({"left":"-390px"});
      });
    });
}


function initFileUploads() {

	$("#photo_input").append('<span class="fakefile"><input id="photo_fake_input"/><input type="button" \
	    value="browse" id="photo_browse_button" class="button"> \
	    <input type="button" value="clear" id="photo_clear_button" class="button"></span>');
	    
	   var pi = $("#id_photo");
	   
	   var fakeinput =  $("#photo_fake_input")[0];
	   $(fakeinput).attr("value", $(pi).val() );
 
	   
	   $(pi).bind("change",{}, function(i,obj) {
	   
	    var fakeinput =  $("#photo_fake_input")[0];
	   
	     $(fakeinput).attr("value", $(pi).val() );

	   });
	   
	    $("#photo_clear_button").click(function() {
	        $(pi).val("");
	
	        $(fakeinput).val("");
	      //  document.getElementById("photo_input").innerHTML = document.getElementById("photo_input").innerHTML; 
	    });
	
}


function setupIconHovers() {
    $(".icon").each(function () {
       
       // Do the tooltips as well
        $(this).qtip({ style: { name: 'blue', tip: true } })
       
       var imgsrc= $(this).attr("src");
       var oversrc = imgsrc.slice(0,imgsrc.search(".png")) + "_over.png"; 
       $(this).mouseover(function() {
        $(this).attr("src",oversrc);     
       });
       $(this).mouseout(function(){
        $(this).attr("src",imgsrc);
       });
    });

}


function confirmLink(url,message) {
    if (confirm(message)) { 
        window.location=url;
    }
}

$(document).ready(function(){
    setPlatform();	
    initFileUploads();
    setupLoginComponent();
    transset();
    setupIconHovers();
    //signupFormDisable();   
});
