// JavaScript Document
$(document).ready(function(){
//why page scroll bar
$('#scroll-pane-why').jScrollPane({scrollbarWidth:28});
//what we do scroll bar
$('#scroll-pane-whatwedo').jScrollPane({scrollbarWidth:28});
//press releases scroll
$('#scroll-pane-pressreleases').scrollable({vertical: true,visibleitems:5,next: '.nextnews3',
			prev: '.prevnews3'});

//news scroll in all the pages
$("#scroll").scrollable({vertical: true,visibleitems:4});
var scrollitems=$("#scroll").find('li').length;
if(scrollitems < 4 ){
    $('.newsScroller').find('a.prev').hide()
    $('.newsScroller').find('a.next').hide()
}
//vertical align function
$('.valign').each(function(){
var outerheight=$(this).parent().height();
var currheight=$(this).height();
var settop=(outerheight-currheight)/2;
$(this).css({marginTop:settop})
})
//news  scroller link function
$('#scroll').find('a').click(function(){
var nid = this.id;
$.ajax({
    type: "POST",
    url: "ajax/getNewsDetails.php",
    data: "newsid="+nid,
    dataType: "html",
    success: function(data){
        if(data.length > 0){
            $("#newspopup").html(data);
            showmodalpopup('newspopup');
            //get record id here call ajax function
            $('#scroll-pane-newspopup').jScrollPane({scrollbarWidth:28});
            return false;
        }
    },
    error: function(msg){
        alert("Error while loading..");
    }
});
}).hover(function(){
$(this).find('span').animate({'padding-left':'15px'})
},function(){
$(this).find('span').animate({'padding-left':'0px'})
})
//press releases  scroller link function
$('.presslisting li div').hover(function(){

$(this).animate({'padding-left':'20px'})

},function(){
$(this).animate({'padding-left':'0px'})

}).click(function(){

 var nid = this.id;
$.ajax({
    type: "POST",
    url: "ajax/getNewsDetails.php",
    data: "newsid="+nid,
    dataType: "html",
    success: function(data){
        if(data.length > 0){
            $("#newspopup").html(data);
            showmodalpopup('newspopup');
            //get record id here call ajax function
            $('#scroll-pane-newspopup').jScrollPane({scrollbarWidth:28});
            return false;
        }
    },
    error: function(msg){
        alert("Error while loading..");
    }
});

})



//global team hover popup function
var default_title;
$('.titlepopup').find('img').hover(function(){
default_title=$(this).attr('title');
if(default_title=='')
{
return ;
}

var thead=default_title.split(',')
var pname=thead[0];
var pdesign=thead[1];
$(this).attr('title','');
var pophtml="<div class='top'><strong>"+pname+"</strong><br/>"+pdesign+"</div><div class='bot'></div>";
$('.titlehoverpopup').html(pophtml).show().css({'left':$(this).offset().left-$(this).width()-20,'top':$(this).offset().top+60})
},function(){

$(this).attr('title',default_title);
$('.titlehoverpopup').hide();
}).click(function(){
    var gtid = this.id;
    $.ajax({
    type: "POST",
    url: "ajax/getGlobalTeamDetails.php",
    data: "gtid="+gtid,
    dataType: "html",
    success: function(data){
        //alert(data);
        if(data.length > 0){
            
            $("#teampopup").find('.gblbiopopup').html(data);
            $('.mask2').show();
            $('.mask2').height($(document).height())
            $('.mask2').animate({opacity:0.8},'fast')
            $('#teampopup').show();
            $('.mask2, #teampopup .popclose ').click(function(){
            $('.mask2').animate({opacity:0},'fast');
            $('.mask2').hide();
            $('#teampopup').hide();
            })
            $('#scroll-pane-teampopup').jScrollPane({scrollbarWidth:28});
        }
    },
    error: function(msg){
        alert("Error while loading..");
    }
    });

})


$('#scroll-pane-globalteam').scrollable({vertical: true,visibleitems:2,next: '.nextnews',
			prev: '.prevnews'});

if($('#scroll-pane-globalteam').find('ul.gtrow').length < 3){
$('.globalteamscroll').find('a.prevnews').hide()
$('.globalteamscroll').find('a.nextnews').hide()

}
//our works page scripts
var slength=$('.workcol').length;
$('.ourworkwraper ').width(slength*167);
$(".scrollable").scrollable({visibleitems:5});

var vlength=$(".awardscroller li").length;
$(".awardscroller ul").width(vlength*150);
$(".awardscroller").scrollable({visibleitems:5,next: '.nexth',
prev: '.prevh'});
$('.mask').css('opacity','0')
$('.ourawardsicon').click(function(){
$('.mask').show();
$('.mask').height($(document).height())
$('.mask').animate({opacity:0.8},'fast')
$('.awards-pop').show();
$('.mask, .awards-pop .popclose ').click(function(){
$('.mask').animate({opacity:0},'fast');
$('.mask').hide();
$('.awards-pop').hide();
})

})

//ourwork pop ajax function call below methods
var ollength=$('.ourworkimgscroller li').length;
$('.ourworkimgscroller  ul').width(ollength*525);
$(".ourworkimgscroller").scrollable({visibleitems:1,next: '.nextho',
			prev: '.prevho'});



//ourworkpopup
/*
$('.ourworkwraper li a').click(function(){
$('.mask').show();
$('.mask').height($(document).height())
$('.mask').animate({opacity:0.8},'fast')
$('.ourworkpopup').show();
$('#scroll-pane').jScrollPane({scrollbarWidth:28});
$('.mask, .ourworkpopup .popclose ').click(function(){
$('.mask').animate({opacity:0},'fast');
$('.mask').hide();
$('.ourworkpopup').hide();
})


})
*/
// news section

//our network function
var mainelement;
$('.worldmap area').hover(function(){
$('.hovermap').hide();
mainelement=$(this);
$(mainelement.attr('href')).show();
var imgpop=$('<img />').attr('src',"images/"+$(this).attr('alt').replace( / /g, "" )+"_ico.png");
$('.maphoverpop').attr('id',$(this).attr('alt').replace( / /g, "" )+'popname').html($(this).attr('alt')).show();
$('.maphoverpop').append(imgpop);
})
$('.hovermap').click(function(){
$('.hovermap').hide();
$('.maphoverpop').hide();
var countryname=$(this).attr('alt').replace( / /g, "" );
//var countryId = $(this).attr('rel');
var countryId = $(this).attr('id');

if(countryname=='europe')
{
$('.zoomeurope').show();

}
else{
//alert(countryId);
showmodalpopup('mapdata')
var countryname=$(this).attr('alt').replace( / /g, "" );
$('.mapdatawraper').html('')
$.ajax({
    type: "GET",
    url: "ajax/mapdata.php",
    dataType: "html",
    data:"cid="+countryId,
    success: function(htmldata) {
	$('.mapdatawraper').html(htmldata);
    $('#scroll-pane-map').jScrollPane({scrollbarWidth:28});
    }

    });

}

})

$('.mainmap, .zoomeurope').bind('mousemove',
				function(e) {

					var $hoveredTxt = $(e.target);

					if(!$hoveredTxt.hasClass('.areaclass'))
					{
						$('.hovermap').hide();
						$('.maphoverpop').hide();
					}


				}
			)

$('.mainmap').bind('mousemove',
				function(e) {

					var $hoveredTxt = $(e.target);

				if(!$hoveredTxt.hasClass('.zoomeurope'))
					{
					$('.zoomeurope').hide();
					}


				}
			)

$('.zoomeurope').find('a').click(function(){
	$('.zoomeurope').hide();

	})




//our offers content pop up starts

$('#ouroffers area').hover(function(){

var contentname=$(this).attr('name');

var offername=$(this).attr('alt');
var filename = $("#offerfilename").val();
      $.ajax({

            type: "GET",

            url: filename,

            dataType: ($.browser.msie) ? "text" : "xml",

            success: function(data) {

                                    var xml;

     if (typeof data == "string") {

       xml = new ActiveXObject("Microsoft.XMLDOM");

       xml.async = false;

       xml.loadXML(data);

     } else {

       xml = data;

     }



            $('.offercontpop .popwraper').html('');

            var $data=$(xml).find('OffersData').find(contentname);

            var maindata= $(xml).find('OffersData').find(contentname).find('description').text();

            $('<strong></strong>').html(offername).appendTo('.offercontpop .popwraper');

                            $('<div  class="offersdata"></div>').html(maindata).appendTo('.offercontpop .popwraper');

                                    $('.offercontpop').show();

                                    var dheight=$('.popwraper').height();

                                    $('.offercontpop .bbg').height(dheight)

            }



            });





})

$('.offerimg').bind('mousemove',

                                                function(e) {

                                                            var $hoveredTxt = $(e.target);



                                                if(!$hoveredTxt.hasClass('.ourofferpopwraper'))

                                                            {

                                                                        if(!$.browser.msie){

                                                            $('.offercontpop').hide();

                                                                 }

                                                    }



                                                }

                                    )

$('#scroll-pane-clientspop').scrollable({ vertical: true,visibleitems:4,next: '.nextnews',
			prev: '.prevnews'});

$('#scroll-pane-managers').scrollable({vertical: true,visibleitems:3,next: '.nextnews2',
                                    prev: '.prevnews2'});

//footer links popups
$('.footerlinks').find('a').click(function(){
showmodalpopup($(this).attr('rel'));
$('#scroll-pane-'+$(this).attr('rel')).jScrollPane({scrollbarWidth:28});
})
//contacts popup
$('a.contacts').click(function(){
showmodalpopup('contactuspopup');
return false;

})
$('#contact_subject').sSelect({ddMaxHeight:'100px'})
$("input.file_1").filestyle({
          image: "images/choose-file.gif",
          imageheight : 22,
          imagewidth : 82,
          width : 147
      });

 /*
  * Contact us form processing
  */
$("#contactfrm").validate({
 errorPlacement: function(error, element) {
  error.appendTo( element.parent().prev());

   }
 })

 $("#contactus").click(function(){
     
    if($("#contactfrm").valid())
    {
        
    }
    var filename = $("#contactfile").val();
    if(filename.length > 0){
        var pos = filename.lastIndexOf(".");
        var strlen = filename.length;
        var ext = filename.substring(pos,strlen);
        ext = ext.toLowerCase();
       
        if(ext != '.pdf' && ext != '.doc' && ext != '.txt'){
            alert("Invalid file, please enter a valid file with .pdf, .doc and .txt extensions");
            return false;
        }
    }

    // captcha code validation in contact us page
    var captchaResponse = $('#recaptcha_response_field').val();
    var captchaChallenge = $('#recaptcha_challenge_field').val();
    //alert(captchaChallenge);
    if(captchaResponse.length == 0){
        $('#validcaptcha').html('<label class="error">This field is required.</label>');
        return false;
    }else{
        $.ajax({
        type: "POST",
        url: "ajax/validateCaptcha.php",
        dataType: "html",
        data:"rc_response="+captchaResponse+'&rc_challenge='+captchaChallenge,
            success: function(data) {
                if(data == '-1'){
                    $('#validcaptcha').html('<label class="error">Invalid captcha code.</labe>');
                    return false;
                }
                else{
                   $('#contactfrm').submit();

                }
            }
        });
                
    }
   
 });


/*
 * uk site changes
 */

$('#insightarea').click(function(){

$('.mask').show();

$('.mask').height($(document).height())

$('.mask').animate({opacity:0.8},'fast')

$('#insightcontent').show();

$('#scroll-pane-insight').jScrollPane({scrollbarWidth:28});

$('.mask, #insightcontent .popclose ').click(function(){

$('.mask').animate({opacity:0},'fast');

$('.mask').hide();

$('#insightcontent').hide();

})

})

$('#frclient').click(function(){

            $('.mask').show();

$('.mask').height($(document).height())

$('.mask').animate({opacity:0.8},'fast')

$('#ourclients').show();

$('#scroll-pane-clients').scrollable({ vertical: true,visibleitems:4,next: '.nextclients',

                                    prev: '.preclients'});

$('.mask, #ourclients .popclose ').click(function(){

$('.mask').animate({opacity:0},'fast');

$('.mask').hide();

$('#ourclients').hide();

})

})





$('#scroll-pane-mediacenter').scrollable({vertical: true,visibleitems:2,next: '.nextnews3',

                                    prev: '.prevnews3'});



$('#media_ourwork_scroll').scrollable({vertical: true,visibleitems:2,next: '.nextclients',

                                    prev: '.preclients'});

//END
})

