 function rotateImages() {
            var oCurPhoto = $('#photoShow div.current');
            var oNxtPhoto = oCurPhoto.next();
            if (oNxtPhoto.length == 0){
                	oNxtPhoto = $('#photoShow div:first');
				}

            oCurPhoto.removeClass('current').addClass('previous');
            oNxtPhoto.css({ opacity: 0.0 }).addClass('current').animate({ opacity: 1.0 }, 3000,
                function() {
                    oCurPhoto.removeClass('previous');
                });
}

$(document).ready(function() {

        setInterval("rotateImages()", 7000);

           
	// Blog feed
	$('#news_feed').miniFeed('http://blog.ibe-erp.com/?feed=atom', { getItemDate: false, nextLinkText: 'More &gt;', limit: 2, getFeedTitle: false });

	var uploadButtonWidth = 61;
	var uploadButtonHeight = 22;
	var videoHandle = null;

	$(".apply_position_link").click(function(e) { 
		var posName = $(this).attr('title');
		if(posName.length > 0)
		{
			$('#apply_position_popup .position_name').html(posName);
			$('#apply_position_popup .position_name').show();
		}
		else
			$('#apply_position_popup .position_name').hide();

		centerWindow("#apply_position_popup");
		$("#apply_position_popup").show();
		$('#apply_position_popup form input[type="text"]').val('');
  	        $("#apply_position_popup .file-info").html('');
		$('#apply_position_popup form input[type="hidden"]').val('');

		e.preventDefault();
	});

	$("#more_info_link").click(function(e) {
		centerWindow("#more_info_popup");
		$("#more_info_popup").show();
		e.preventDefault();
	});

	$("#watch_video_link").click(function(e) {
		if(videoHandle != null)
			$("#video_popup").prepend(videoHandle);
		centerWindow("#video_popup");
		$("#video_popup").show();

		e.preventDefault();
	});

	$("#more_info_form").submit(function(e) {
		var data = {
			name: $('#more_info_popup form input[name="name"]').val(),
			email: $('#more_info_popup form input[name="email"]').val()
		};

		$('#more_info_popup .error').html('');
		var error = '';
		if(data.name.length == 0)
			error += "Please, enter your name!<br>"
		if(data.email.length == 0)
			error += "Please, enter your e-mail!<br>"
		else if(!checkEmail(data.email))
			error += "Please, enter a proper e-mail address!<br>"

		if(error.length > 0)
		{
			$('#more_info_popup .error').show();
			$('#more_info_popup .error').append(error);
		}
		else
		{
			$.post("../more_info.php", 
				data,
				function(output) {
					 $("#apply_position_done p").html('');
					 if(output == 1)
						 $("#apply_position_done p").append("Your application was successfully sent!");
					 else if(output == 0)
						 $("#apply_position_done p").append("We are sorry, but we were unable to deliver your request. Please, try again later!");
					 $("#more_info_popup").hide();

					 centerWindow("#apply_position_done");
					 $("#apply_position_done").show();
				}
			);
		}
			
		e.preventDefault();
	});


	var countries = countryList();
	var i = 0;
	for(i = 0; i < countries.length; i++)
		$("#apply_position_popup form .row select").append('<option value="'+countries[i]+'">'+countries[i]+'</option>');

	$("#apply_position_form").submit(function(e) {
		var data = {
			position: $('#apply_position_popup .position_name').html(),
			name: $('#apply_position_popup form input[name="name"]').val(),
			email: $('#apply_position_popup form input[name="email"]').val(),
			phone: $('#apply_position_popup form input[name="phone"]').val(),
			country: $('#apply_position_popup form select').val(),
			resume: $('#apply_position_popup form input[name="filename"]').val(),
			realname: $('#apply_position_popup form input[name="realname"]').val()
		};

		$('#apply_position_popup .error').html('');
		var error = '';
		if(data.name.length == 0)
			error += "Please, enter your name!<br>"
		if(data.email.length == 0)
			error += "Please, enter your e-mail!<br>"
		else if(!checkEmail(data.email))
			error += "Please, enter a proper e-mail address!<br>"
		if(data.phone.length == 0)
			error += "Please, enter your phone!<br>"
		if(data.resume.length == 0)
			error += "Please, attach your resume!<br>"

		if(error.length > 0)
		{
			$('#apply_position_popup .error').show();
			$('#apply_position_popup .error').append(error);
		}
		else
		{
			$.post("../mail.php", 
				data,
				function(output) {
					 $("#apply_position_done p").html('');
					 if(output == 1)
						 $("#apply_position_done p").append("Your application was successfully sent!");
					 else if(output == 0)
						 $("#apply_position_done p").append("We are sorry, but we were unable to deliver your application. Please, try again later!");
					 $.swfupload.getInstance('#resume_uploader').setButtonDimensions(uploadButtonWidth,uploadButtonHeight);
					 $("#apply_position_popup").hide();

					 centerWindow("#apply_position_done");
					 $("#apply_position_done").show();
				}
			);
		}
			
		e.preventDefault();
	});

	$('#more_info_popup .close').click(function(e) {
		 $("#more_info_popup").hide();
		 e.preventDefault();
	});


	$('#video_popup .close').click(function(e) {
		 $("#video_popup").hide();
		 e.preventDefault();
		 videoHandle = $("#video_popup iframe").detach();
	});

	$('#apply_position_popup .close').click(function(e) {
		 $("#apply_position_popup").hide();
		 e.preventDefault();
	});

	$('#apply_position_done .close').click(function(e) {
		 $("#apply_position_done").hide();
		 e.preventDefault();
	});

    $('#resume_uploader').swfupload({
        // Backend Settings
        upload_url: "/swfupload/upload.php",    // Relative to the SWF file (or you can use absolute paths)
        
        // File Upload Settings
        file_size_limit : "102400", // 100MB
        file_types : "*.*",
        file_types_description : "All Files",
        file_upload_limit : "0",
        file_queue_limit : "1",
	/*debug: true,
	debug_handler: function(msg) { console.log(msg); },*/
    
        // Button Settings
        button_placeholder_id : "resume_upload_link",
        button_width: uploadButtonWidth,
        button_height: uploadButtonHeight,
	button_image_url: "http://ibe-erp.com/images/UploaderButton.png",
	button_cursor : SWFUpload.CURSOR.HAND,
	button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES,
	button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        
        // Flash Settings
	flash_url: "http://ibe-erp.com/swfupload/Flash/swfupload.swf"
        
    });

   $('#resume_uploader')
        .bind('fileQueued', function(event, file){
            // start the upload once a file is queued
            $(this).swfupload('startUpload');
        })
	.bind('uploadStart', function(event, file) {
	    $("#apply_position_popup .progress").show();
	    $.swfupload.getInstance(this).setButtonDimensions(0,0);
	    $("#apply_position_popup .file-info").html(file.name+' '+file.size+' B');
	    $('#apply_position_popup form .row input[type="submit"]').hide(); 
	})
	.bind('uploadProgress', function(event, file, bytes, total) {
	    $("#apply_position_popup .progress").css({ width: Math.round(bytes/total * 100) + "%" });
	})
        .bind('uploadComplete', function(event, file){
	    $("#apply_position_popup .progress").hide();
	    $('#apply_position_popup form .row input[type="submit"]').show(); 
        })
        .bind('uploadSuccess', function(event, file, data, response){
	    var out = $.parseJSON(data);
	    $("#apply_position_popup .file-info").append(' <a href="#" class="remove">Remove</a>');
	    $('#apply_position_popup form input[name="filename"]').val(out.realname);
	    $('#apply_position_popup form input[name="realname"]').val(out.name);
        })
	.bind('uploadError', function(event, file, errorcode, message) {
	    switch(errorcode)
	    {
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			break;
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
		        alert('Upload cancelled!');
			break;
		default:
	        	alert('Upload failed - '+message);
	    };
	    $("#apply_position_popup .file-info").html('');
	    $.swfupload.getInstance(this).setButtonDimensions(uploadButtonWidth,uploadButtonHeight);
	    $('#apply_position_popup form .row input[type="submit"]').show(); 
	})
	.bind('fileQueueError', function(event, file, errorcode, message) {
	    alert('You can only send 1 file!');
	});

        $("#apply_position_popup .progress").click(function(e) { 
            $('#resume_uploader').swfupload('stopUpload');
            $('#resume_uploader').swfupload('cancelUpload');
	    $("#apply_position_popup .progress").hide();
	    e.preventDefault();
	});

	$("#apply_position_popup .file-info").delegate('.remove', 'click', function(e) { 
	    $("#apply_position_popup .file-info").html('');
	    $.swfupload.getInstance('#resume_uploader').setButtonDimensions(uploadButtonWidth,uploadButtonHeight);
	    e.preventDefault();
	    $.post("/swfupload/upload.php?attachment=1", 
			{ name: $('#apply_position_popup form input[name="filename"]').val() },
			function(output) {
		});
	    $('#apply_position_popup form input[type="hidden"]').val('');

	});
});

function centerWindow(win)
{
	 var top = $(window).height()/2 - $(win).height()/2;
	 var left = $(window).width()/2 - $(win).width()/2;
	 $(win).css('top',top);
	 $(win).css('left',left);
}

function checkEmail(inputvalue){	
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue))
	return true;
    else
	return false;
}

function countryList()
{
	return Array(
		"United States",
		"India",
		"Afghanistan",
		"Albania",
		"Algeria",
		"Andorra",
		"Angola",
		"Antigua and Barbuda",
		"Argentina",
		"Armenia",
		"Australia",
		"Austria",
		"Azerbaijan",
		"Bahamas",
		"Bahrain",
		"Bangladesh",
		"Barbados",
		"Belarus",
		"Belgium",
		"Belize",
		"Benin",
		"Bhutan",
		"Bolivia",
		"Bosnia and Herzegovina",
		"Botswana",
		"Brazil",
		"Brunei",
		"Bulgaria",
		"Burkina Faso",
		"Burundi",
		"Cambodia",
		"Cameroon",
		"Canada",
		"Cape Verde",
		"Central African Republic",
		"Chad",
		"Chile",
		"China",
		"Colombi",
		"Comoros",
		"Congo (Brazzaville)",
		"Congo",
		"Costa Rica",
		"Cote d'Ivoire",
		"Croatia",
		"Cuba",
		"Cyprus",
		"Czech Republic",
		"Denmark",
		"Djibouti",
		"Dominica",
		"Dominican Republic",
		"East Timor (Timor Timur)",
		"Ecuador",
		"Egypt",
		"El Salvador",
		"England",
		"Equatorial Guinea",
		"Eritrea",
		"Estonia",
		"Ethiopia",
		"Fiji",
		"Finland",
		"France",
		"Gabon",
		"Gambia, The",
		"Georgia",
		"Germany",
		"Ghana",
		"Greece",
		"Grenada",
		"Guatemala",
		"Guinea",
		"Guinea-Bissau",
		"Guyana",
		"Haiti",
		"Honduras",
		"Hong Kong",
		"Hungary",
		"Iceland",
		"Indonesia",
		"Iran",
		"Iraq",
		"Ireland",
		"Israel",
		"Italy",
		"Jamaica",
		"Japan",
		"Jordan",
		"Kazakhstan",
		"Kenya",
		"Kiribati",
		"Korea, North",
		"Korea, South",
		"Kuwait",
		"Kyrgyzstan",
		"Laos",
		"Latvia",
		"Lebanon",
		"Lesotho",
		"Liberia",
		"Libya",
		"Liechtenstein",
		"Lithuania",
		"Luxembourg",
		"Macau",
		"Macedonia",
		"Madagascar",
		"Malawi",
		"Malaysia",
		"Maldives",
		"Mali",
		"Malta",
		"Marshall Islands",
		"Mauritania",
		"Mauritius",
		"Mexico",
		"Micronesia",
		"Moldova",
		"Monaco",
		"Mongolia",
		"Morocco",
		"Mozambique",
		"Myanmar",
		"Namibia",
		"Nauru",
		"Nepa",
		"Netherlands",
		"New Zealand",
		"Nicaragua",
		"Niger",
		"Nigeria",
		"Northern Ireland",
		"Norway",
		"Oman",
		"Pakistan",
		"Palau",
		"Palestine",
		"Panama",
		"Papua New Guinea",
		"Paraguay",
		"Peru",
		"Philippines",
		"Poland",
		"Portugal",
		"Qatar",
		"Romania",
		"Russia",
		"Rwanda",
		"Saint Kitts and Nevis",
		"Saint Lucia",
		"Saint Vincent",
		"Samoa",
		"San Marino",
		"Sao Tome and Principe",
		"Saudi Arabia",
		"Scotland",
		"Senegal",
		"Serbia",
	       	"Montenegro",
		"Seychelles",
		"Sierra Leone",
		"Singapore",
		"Slovakia",
		"Slovenia",
		"Solomon Islands",
		"Somalia",
		"South Africa",
		"Spain",
		"Sri Lanka",
		"Sudan",
		"Suriname",
		"Swaziland",
		"Sweden",
		"Switzerland",
		"Syria",
		"Taiwan",
		"Tajikistan",
		"Tanzania",
		"Thailand",
		"Togo",
		"Tonga",
		"Trinidad and Tobago",
		"Tunisia",
		"Turkey",
		"Turkmenistan",
		"Tuvalu",
		"Uganda",
		"Ukraine",
		"United Arab Emirates",
		"Uruguay",
		"Uzbekistan",
		"Vanuatu",
		"Vatican City",
		"Venezuela",
		"Vietnam",
		"Wales",
		"Yemen",
		"Zambia",
		"Zimbabwe"
	);
}

