// JavaScript Document
//Declare Global Variables
g_currimage = '1';
g_imgname = '1';
//========= HOME PAGE BANNER =========
 var swflink = "javascript:void(0)";
 var flashvars = false;
 var params = {};
 params.menu = "false";
 params.bgcolor = "#000000";
 params.wmode = "transparent";
 var attributes = false;
 swfobject.embedSWF("flash/expat_banner.swf", "expat_banner", "952", "278", "9", swflink, flashvars, params, attributes);
//======================================
$(document).ready(function() {
	//$('#quotearea').cycle({fx:'scrollRight', delay: -1000, cleartypeNoBg: true });	
	
	// TABS
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	// TABS
	$(".tab_contentmedia").hide(); //Hide all content
	$("ul.tabsmedia li:first").addClass("active").show(); //Activate first tab
	$(".tab_contentmedia:first").show(); //Show first tab content

$("ul.tabsmedia li").click(function() {
		$("ul.tabsmedia li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_contentmedia").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});
	
	$("#propertycarousel").jCarouselLite({
        btnNext: "#cnext",
        btnPrev: "#cprev",
		scroll: 4,
		visible: 4
    });
	
	$('#con_locs a').each(function(){
           var dWidth 	= parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
           var dHeight 	=  parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
			$(this).fancybox({
				'width'				:dWidth,
				'height'			:dHeight,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
				'titleShow'			: false
			});
      });
	$('#Map area').each(function(){
           var dWidth 	= parseInt($(this).attr('href').match(/width=[0-9]+/i)[0].replace('width=',''));
           var dHeight 	=  parseInt($(this).attr('href').match(/height=[0-9]+/i)[0].replace('height=',''));
			$(this).fancybox({
				'width'				:dWidth,
				'height'			:dHeight,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
				'titleShow'			: false
			});
      });

	// CONTACT CONTENT
	$(".contact_content").hide(); //Hide all content
	$(".contact_content:first").show(); //Show first con content
	
	$('#sel_contact').change(function(){
		$(".contact_content").hide(); //Hide all content
		$('#con' + $(this).val()).fadeIn(); 
		return false;
	});
	
	$("#videoplaylist").jCarouselLite({
        btnNext: "#vnext",
        btnPrev: "#vprev",
		scroll: 1,
		visible: 3
    });
	
	//Events Carousel
	$("#eventscarousel").jCarouselLite({
        btnNext: "#cnext",
        btnPrev: "#cprev",
		scroll: 2,
		visible: 4
    });

	//EMI Carousel
	$("#emicarousel").jCarouselLite({
        btnNext: "#cnext",
        btnPrev: "#cprev",
		scroll: 2,
		visible: 5
    });

	//Values Carousel
	$("#valuescarousel").jCarouselLite({
		btnNext: "#cnext",
		btnPrev: "#cprev",
		circular: true,
		scroll: 1,
		visible: 1,
		auto: 5000,
		hoverPause: true,
		beforeStart: function(a) {
			$(a).parent().fadeTo(500, 0);
			var bg = $(a).find('img').attr('src');
			$("#valuescarousel").css({
				backgroundImage: "url("+bg+")"
			}, 100);
		},
		afterEnd: function(a) {
			$(a).parent().fadeTo(500, 1);
		}
    });
	
	//Quotes Carousel
	$("#quotearea").jCarouselLite({
		circular: true,
		scroll: 1,
		visible: 1,
		auto: 7000,
		speed: 500,
		hoverPause: true
    });

$('#videoplaylist img').each(function() {
            $(this).hover(function() {
                $(this).stop().animate({ opacity: 0.5 }, 300);
            },
           function() {
               $(this).stop().animate({ opacity: 1.0 }, 300);
           });
        });
	$("input[type=file]").filestyle({ 
     image: "images/frm-browse.gif",
     imageheight : 33,
     imagewidth : 74,
     width : 220
    });
	
	$("#file_upload").uploadify({
		'uploader'       : '/group/scripts/uploadify.swf',
		'script'         : '/group/scripts/uploadify.php',
		//'cancelImg'      : '/group/scripts/cancel.png',
		'folder'         : '/group/scripts/uploads',
		'hideButton' 	 : 'true',
		'wmode'       	 : 'transparent',
		'width'			 : 74,
		'height'		 : 33,
		'queueID'        : 'fileQueue',
		'fileDesc'       : 'Image Files',
		'fileExt'        : '*.doc;*.pdf',
		'auto'           : true,
		'multi'          : false,
		'sizeLimit'   	 : 563200,
		onSelect         : function (evt, queueID, fileObj, errorObj) {
							$('input[type="image"]').attr('disabled','disabled');
						   },
		onComplete       : function (evt, queueID, fileObj, response, data) {
							$('#file_preview').html(fileObj.name+ ' is uploaded');
							$('#file_input').html('<input name=\"file\" type=\"hidden\" value=\"' + fileObj.name + '\" />');
							$('#file_newupload_con').html('<a href=\"javascript:void(0)\" rel=\"' + fileObj.name + '\">Upload a new file</a>');
							g_currimage = fileObj.name;
							$("#file_upload_con").css("left",-3000);
							$("#file_newupload_con").fadeIn();
							$('input[type="image"]').removeAttr('disabled');
						   },
		onError          : function (evt, queueID, fileObj, errorObj) {
							$('#fileQueue').html('&nbsp;&nbsp;&nbsp;<span style=\'color:#990000;\'>' + errorObj.type + ' Error: ' + errorObj.info + '</span>');
							setTimeout( function() { $('#fileQueue').html(''); }, 5000 );
							$('input[type="image"]').removeAttr('disabled');
						   }
	});

	// .delegate() function
	$('#file_newupload_con').delegate('a', 'click', function(e){
	  
	    g_imgname = $(this).attr("rel");
		// Ajax delete file
		$.ajax({
		   type: "POST",
		   url: "scripts/file_delete.php",
		   data: "name="+g_imgname,
		   success: function(msg){
			 //alert( "Data Saved: " + msg );
		   }
		 });
		$('#file_preview').html('');
		$("#file_newupload_con").hide();
		$("#file_upload_con").css("left",0);
	});

	//Accordion for management
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {
		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
	 });
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	//CLOSES ALL S ON PAGE LOAD
	$('.accordionContent').hide();
	
	
	//PopUp Ad
	setTimeout( function() { $('#popupad').fadeIn(2000).delay(15000).fadeOut(); }, 3000 );
	$("#closepopupad").click(function() {
		$('#popupad').hide();					   
	});

});

//=======================================

 var flashvars = true;
 var params = {};
 params.menu = "false";
 params.bgcolor = "#000000";
 params.wmode = "transparent";
 params.allowfullscreen = "true";
 params.allowscriptaccess = "always";
 var attributes = {};
 attributes.id = "iplayer";
 attributes.name = "iplayer";
 swfobject.embedSWF("http://www.youtube.com/v/hNtTfip14SI&fs=1", "videobox", "352", "240", "9", false, flashvars, params, attributes);

function initPlayer(theFile) { 
        deletePlayer('videowrapper', 'videoplaceholder', 'iplayer'); 
        createPlayer('videoplaceholder', 'iplayer', theFile);
}

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}

function createPlayer(thePlaceholder, thePlayerId, theFile) {
 var flashvars = true;
 var params = {};
 params.menu = "false";
 params.bgcolor = "#000000";
 params.wmode = "transparent";
 params.allowfullscreen = "true";
 params.allowscriptaccess = "always";
 var attributes = {};
 attributes.id = "iplayer";
 attributes.name = "iplayer";
 swfobject.embedSWF(theFile+"&fs=1", thePlaceholder, "352", "240", "9", false, flashvars, params, attributes);
}

//==============LOAD EVENT=================
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
//=======================================
function invalidemail(s)
{
  res=0;
  len=s.length;

   for(i=0;i<len;i++)
     { 
       if(s.charAt(i)=='@' )
	 
   for(j=i;j<len;j++)
            {
              if(s.charAt(j)=='.')
                  res=1;
             }
     }  
if (res==0)
    return true; 
  else
     return false; 
}

function check_frmcontact(frm) {
	if (frm.Message.value=="" || frm.Message.value=="Your query or message")
    {
	  frm.Message.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Name.value=="" || frm.Name.value=="Name")
    {
	  frm.Name.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Email.value=="" || frm.Email.value=="Email")
    {
	  frm.Email.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (invalidemail(frm.Email.value))
    {
	  frm.Email.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Contact_Number.value=="" || frm.Contact_Number.value=="Contact Number")
    {
	  frm.Contact_Number.style.backgroundColor='#F8E7E7';
      return false;
    }
	
	return true;
}

function check_frmreview(frm) {
	if (frm.Feedback.value=="" || frm.Feedback.value=="Your Feedback")
    {
	  frm.Feedback.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Name.value=="" || frm.Name.value=="Name")
    {
	  frm.Name.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Location.value=="" || frm.Location.value=="Location")
    {
	  frm.Location.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Company.value=="" || frm.Company.value=="Company")
    {
	  frm.Company.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Designation.value=="" || frm.Designation.value=="Designation")
    {
	  frm.Designation.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Email.value=="" || frm.Email.value=="Email")
    {
	  frm.Email.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (invalidemail(frm.Email.value))
    {
	  frm.Email.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Contact_Number.value=="" || frm.Contact_Number.value=="Contact Number")
    {
	  frm.Contact_Number.style.backgroundColor='#F8E7E7';
      return false;
    }
	
	return true;
}
function check_frmcv(frm) {
	if (g_imgname.toString()==g_currimage.toString())
    {
	  // frm.file.focus(); Throws error in all IE versions
	  $('#file_preview').html('Please select your CV file to upload!');
      return false;
    }
	return true;
}
function check_frmcareers(frm) {
	if (frm.Name.value=="" || frm.Name.value=="Your Name")
    {
	  frm.Name.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Preferred_Location.value=="" || frm.Preferred_Location.value=="Preferred Location")
    {
	  frm.Preferred_Location.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Experience.value=="" || frm.Experience.value=="Experience")
    {
	  frm.Experience.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Educational_Qualification.value=="" || frm.Educational_Qualification.value=="Educational Qualification")
    {
	  frm.Educational_Qualification.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (frm.Covering_Letter.value=="" || frm.Covering_Letter.value=="Write your covering letter here")
    {
	  frm.Covering_Letter.style.backgroundColor='#F8E7E7';
      return false;
    }
	if (g_imgname.toString()==g_currimage.toString())
    {
	  // frm.file.focus(); Throws error in all IE versions
	  $('#file_preview').html('Please select your CV file to upload!');
      return false;
    }
	return true;
}

//Google Analytics tracking code

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22371500-1']);
  _gaq.push(['_setDomainName', '.expat-group.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

//Google Analytics tracking code
