jQuery.fn.exists = function() {
    return (this.length > 0);
};


var twodots = {
	init: function() {
	
	    $("#gender_dropdown").change(
	        function () {
	            if ($("#gender_dropdown").val() == "male") {
	                $("#male_sizes").fadeIn(700);
	                $("#female_sizes").fadeOut(700);
	            } else if ($("#gender_dropdown").val() == "female") {
	                $("#female_sizes").fadeIn(700);
	                $("#male_sizes").fadeOut(700);
	            }
	        }
	    );
	
	    $("#resume_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/resume_upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'resume_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.pdf;*.doc;*.docx;*.rtf',
            'width': '72',
            'height': '19',
            'sizeLimit': 4000000,
            'auto': true,
            'multi': false,
            'wmode': 'transparent',
            'displayData': 'percentage',
            'scriptData':  {'staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#resume_icon").attr('src','../images/resume_icon_check.gif');
	    		$("#staff_resume_file_link").attr('href','../account/resumes/'+d);
	    		$("#staff_resume_file_link").html(d);
            }
        });
        
        
        $("#photo_1_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'width': '72',
            'height': '19',
            'sizeLimit': 4000000,
            'auto': true,
            'multi': false,
            'wmode': 'transparent',
            'displayData': 'percentage',
            'scriptData':  {'photo_index': '1','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_1").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_1").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_1").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_2_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'width': '72',
            'height': '19',
            'sizeLimit': 4000000,
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '2','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_2").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_2").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_2").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_3_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'width': '72',
            'height': '19',
            'sizeLimit': 4000000,
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '3','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_3").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_3").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_3").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_4_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'sizeLimit': 4000000,
            'width': '72',
            'height': '19',
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '4','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_4").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_4").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_4").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_5_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'sizeLimit': 4000000,
            'width': '72',
            'height': '19',
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '5','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_5").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_5").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_5").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_6_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'sizeLimit': 4000000,
            'width': '72',
            'height': '19',
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '6','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_6").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_6").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_6").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        $("#photo_7_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'sizeLimit': 4000000,
            'width': '72',
            'height': '19',
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '7','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_7").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_7").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_7").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
        
        
        $("#photo_8_upload").fileUpload({
            'uploader': '../js/uploader.swf',
            'cancelImg': '../images/cancel.png',
            'script': '../ajax/upload.php',
            'buttonImg': '../images/2d_upload.gif',
            'fileDataName': 'staff_file',
    		'fileDesc': 'Image Files',
    		'fileExt': '*.jpg;*.jpeg',
            'sizeLimit': 4000000,
            'width': '72',
            'height': '19',
            'auto': true,
            'multi': false,
            'displayData': 'speed',
            'scriptData':  {'photo_index': '8','staff_id': $("#form_sid").html()},
            onComplete: function (a, b, c, d, e) {
	    		$("#staff_photo_8").attr('src','../account/photos/thumbs/'+d);
    			$("#staff_photo_href_8").attr('href','../account/photos/'+d);
    			$("#staff_photo_href_8").attr('class','lightbox');
                $('a.lightbox').lightBox({fixedNavigation:true});
            }
        });
	
	
	
	
        $("#market_state").change(function () {
            if ($("#markets").css("display") == "none") {
                $("#markets").fadeIn(1000);
            }
        });
        
        $('#container-1').tabs();
        
        $('#slideshow').cycle({
                sync: 1,
                fx: 'fade',
                speed: 3500,
                timeout: 6000
            });
        
        
    }
}

jQuery(document).ready(function() {
	twodots.init();
});

function get_new_file_name() {
    //alert(event);
    return true;
}



function add_remove_shift(shift_id) {
    if ($("#staff_shift_"+shift_id).exists()) {
        // success message
        $("#staff_shift_"+shift_id).remove();
        remove_shift(shift_id);
    } else {
        // add a loading thing
        $("#applied_jobs").append('<div id="shift_loading" style="color:#e44d18"><img src="../images/shift-loading.gif" border="0" alt="Loading" /> Loading</div>');
        add_shift(shift_id);

    }
}

function append_shift(data) {
    $("#applied_jobs").append(data);
    // then remove the loading thing
    $("#shift_loading").remove();
}


function add_shift(shift_id) {
    $.get("../ajax/ajax.functions.php", { action: "add_shift", shift_id: shift_id },
        function(data) {
            append_shift(data);
        }
    );
}

function remove_shift(shift_id) {
    $.get("../ajax/ajax.functions.php", { action: "remove_shift", shift_id: shift_id });
}

function preloadImages () { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore () { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj (n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage () { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

