//plugin
jQuery.fn.topLink = function(settings) {
	settings = jQuery.extend({
		min: 1,
		fadeSpeed: 200,
		ieOffset: 50
	}, settings);
	return this.each(function() {
		//listen for scroll
		var el = $(this);
		el.css('display','none'); //in case the user forgot
		$(window).scroll(function() {
			//stupid IE hack
			if(!jQuery.support.hrefNormalized) {
				el.css({
					'position': 'absolute',
					'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
				});
			}
			if($(window).scrollTop() >= settings.min)
			{
				el.fadeIn(settings.fadeSpeed);
			}
			else
			{
				el.fadeOut(settings.fadeSpeed);
			}
		});
	});
};

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

$(function(){

	$.preloadCssImages();
	
	
	$.address.change(function(event) {
		// do something depending on the event.value property, e.g.
		// $('#content').load(event.value + '.xml');
	});
	$('.navigation ul li a').click(function() {
		$.address.value($(this).attr('href'));
	});
	
	
	$('.random_thoughts').cycle({
		fx: 'blindY' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
	$('#top-link').topLink({
		 min: 100,
		 fadeSpeed: 500
	});
	
	$('#top-link').click(function(){
		resetAllPages();						  
	});
		 
	$('#slider').nivoSlider({
		effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
		slices:15,
		animSpeed:500,
		pauseTime:3000,
		startSlide:0, //Set starting Slide (0 index)
		directionNav:false, //Next & Prev
		directionNavHide:true, //Only show on hover
		controlNav:true, //1,2,3...
		controlNavThumbs:false, //Use thumbnails for Control Nav
		controlNavThumbsFromRel:false, //Use image rel for thumbs
		controlNavThumbsSearch: '.jpg', //Replace this with...
		controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
		keyboardNav:true, //Use left & right arrows
		pauseOnHover:true, //Stop animation while hovering
		manualAdvance:false, //Force manual transitions
		captionOpacity:0.8, //Universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} //Triggers after all slides have been shown
	});
    
	$('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            if ($target.length) {
            
                var targetOffset = $target.offset().top;
                
                $('html,body').animate({scrollTop: targetOffset}, 1000);
                    
                return false;
                
            }
            
        }
        
    });
	
	$('.navigation ul li:last-child').css('background','none');
	$('.page_nav ul li:last-child').css('background','none');
	$('li.profile_name:last-child').css('background','none');
	$('div.our_team_content div:last-child').css('paddingRight','0px');
	
	
	
	$('ul.accordion-content-slider').bxSlider({
		alignment: 'vertical',        // 'horizontal', 'vertical' - direction in which slides will move
		controls: false,                 // determines if default 'next'/'prev' controls are displayed
		speed: 500,                     // amount of time slide transition lasts (in milliseconds)
		pager: true,                    // determines if a numeric pager is displayed (1 2 3 4...)
		pager_short: false,             // determines if a 'short' numeric pager is displayed (1/4)
		pager_short_separator: ' / ',   // text to be used to separate the short pager
		margin: 0,                      // if 'horizontal', applies a right margin to each slide, if 'vertical' a
		                                // bottom margin is applied. example: margin: 50
		next_text: 'next',              // text to be displayed for the 'next' control
		next_image: '',                 // image to be used for the 'next' control
		prev_text: 'prev',              // text to be displayed for the 'prev' control
		prev_image: '',                 // image to be used for the 'prev' control
		auto: false,                    // determines if slides will move automatically
		pause: 3500,                    // time between each slide transition (auto mode only) 
		auto_direction: 'next',         // order in which slides will transition (auto mode only)
		auto_hover: true,               // determines if slideshow will pause while mouse is hovering over slideshow
		auto_controls: false,           // determines if 'start'/'stop' controls are displayed (auto mode only)
		ticker: false,                  // determines if slideshow will behave as a constant ticker
		ticker_controls: false,         // determines if 'start'/'stop' ticker controls are displayed (ticker mode only)
		ticker_direction: 'next',       // order in which slides will transition (ticker mode only)
		ticker_hover: true,             // determines if slideshow will pause while mouse is hovering over slideshow
		stop_text: 'stop',              // text to be displayed for the 'stop' control
		start_text: 'start',            // text to be displayed for the 'start' control
		wrapper_class: 'description'  // class name to be used for the outer wrapper of the slideshow
	});
	
	$('div#accordion> div').hide(); 
	
	$('div#accordion> h3').hover(function(){
		$(this).css('color', '#C280AC');
	}		
	,function(){
		$(this).css('color', '#615D5C');
	});
	
	$('div#accordion> h3').click(function() {
		$(this).addClass("active");
		$(this).next('div').slideDown('fast',function() {
			//$(this).prev('h3').removeClass("active");
		})
		.siblings('div:visible').slideUp('fast',function() {
			$(this).prev('h3').removeClass("active");
		});
	});
	
	
	
	$('ul.our_team_nav li a').click(function(){
		var linkID = $(this).attr("href");
			
		updateOurTeamContent(linkID);
	});
	
	$('ul.whoarewe_nav li a').click(function(){
		var linkID = $(this).attr("href");
		
		updateWhoareweContent(linkID);
	});	
	
	
	$(".navigation ul li a").click(function(){
		  /*
		  var linkID = $(this).attr("href");	
		  updateWhoareweContent("#crystaleyes");	  
		  updateOurTeamContent("#team");
		  $(".client_info").fadeOut("slow");
		  $(".logo_group").slideDown("slow");
		  $("div.description").hide();
		  $("div#accordion h3").removeClass("active");
		  $("div.meet_us_sec").show().siblings('div').hide();
		  if(linkID == "#who-are-we")
		  {
			  var buttonLink = $("ul.whoarewe_nav li");
			  if(buttonLink.children().attr("href") == "#crystaleyes")
			  {
				  activateLink(buttonLink[0]);
			  }
		  }
		  else if(linkID == "#our-team")
		  {
			  var buttonLink = $("ul.our_team_nav li");
			  if(buttonLink.children().attr("href") == "#team")
			  {
				  activateLink(buttonLink[0]);
			  }
		  }
		  else if(linkID == "#our-clients")
		  {
			  
		  }
		  else if(linkID == "#our-expertise")
		  {
	
		  }
		  else if(linkID == "#contact-us")
		  {
			  var buttonLink = $("ul.contact_nav li");
			  if(buttonLink.children().attr("href") == "#meet_us")
			  {
				  activateLink(buttonLink[0]);
			  }
		  }
		  */
		  
		  resetAllPages();
	});
	
	$("div.feedback_form").hide();
	
	
	$(".page_nav ul li").click(function(){
		  activateLink(this);
	});
		
	$("ul.contact_nav li").click(function(){
	  $(this).addClass("active").siblings("li.active").removeClass("active");
	  var linkID = $(this).children().attr('href');
	  
	  if(linkID == "#meet_us")
	  {
		  $("div.meet_us_sec").show().siblings('div').hide();
	  }
	  else if(linkID == "#feedback_form")
	  {
		  $("div.feedback_form").show().siblings('div').hide();
	  }
	});
	
	
	$("#submit").click(function(){
	  
	  var hasError = false;
	  var emailReg = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
	  
	  var nameVal = $("#name").val();
	  if(nameVal == '') {
	   $("#name").css("borderColor", "#6E2B61");
	   hasError = true;
	  }
	  else
	  {
		$("#name").css("borderColor", "#dbadc5");		  
	  }
	  
	  var emailFromVal = $("#email").val();
	  if(emailFromVal == '') {
	   $("#email").css("borderColor", "#6E2B61");
	   hasError = true;
	  }/* 
	  else if(!emailReg.test(emailFromVal)) {
	   $("#email").css("borderColor", "#6E2B61");
	   hasError = true;
	  }*/
	  else
	  {
		$("#email").css("borderColor", "#dbadc5");
	  }	  
	  
	  var telephoneVal = $("#telephone").val();
	  if(telephoneVal == '') {
	   $("#telephone").css("borderColor", "#6E2B61");
	   hasError = true;
	  }
	  else
	  {
		$("#telephone").css("borderColor", "#dbadc5");
	  }
	  
	  
	  var messageVal = $("#message").val();
	  if(messageVal == '') {
	   $("#message").css("borderColor", "#6E2B61");
	   hasError = true;
	  }
	  else
	  {
		$("#message").css("borderColor", "#dbadc5");
	  }
	  
	  if(hasError == false) {
			$(this).hide();
			$(".error").hide();
			$(".form_field div.button_holder").append('<img src="images/ajax-loader.gif" alt="Loading" id="loading" />');
			
			$.post("sendemail.php",
   				{ name: nameVal, email: emailFromVal, telephone: telephoneVal, message: messageVal },
   					function(data){
							$("#loading").remove();
							$(".feedback_form form").after("<p class='success_message'>Your email was successfully sent.</p>");
							$('form').clearForm()
   					}
				 );
		}
	  
	  return false;
	 });
	
	$(".client_info").hide();
	
	var currLinkID;
	
	$("td.logo_link a").click(function()
	{
		currLinkID = $(this).attr("href");
		$(".logo_group").slideUp("slow");
		$(currLinkID).fadeIn("slow");
	});	
	
	$("p.back_link>a").click(function()
	{
		$(currLinkID).fadeOut("slow");
		$(".logo_group").slideDown("slow");
	});	
	
	$('li.profile_name').hover(function(){
		$(this).addClass("profileHover");
	},function(){
		$(this).removeClass("profileHover");		 
	});
	
	$('li.profile_name').click(function(){
		$(this).addClass("active").siblings('li').removeClass("active");
		var profileID = $(this).attr("id");		
		if(profileID == "shalini_rao")
		{
			$('div.director_profile').html("<p>With 18 years of experience across organisations such as McKinsey, Gillette, Mars &amp;  Marico, Shalini brings a strong blend of consulting and Marketing leadership experience.</p><p>Last role - Practice expert at McKinsey for FMCG, Retail &amp; Media. Prior to that she was Head of marketing at Mars (Pedigree/Snickers) for 4 years and was responsible for creating the pet food category in the country. Even at Marico, she was involved in extending the franchise of Saffola.</p><p>Shalini also undertakes leadership mentoring projects.</p>");
		}
		else if(profileID == "amar_wadhwa")
		{
			$('div.director_profile').html("<p>16 yrs of experience in brand strategy, consulting, research and media at Cheil Worldwide (Samsung), Publicis, BBDO, Accenture, Leo Burnett, IMRB.</p><p>Last Role – National Strategy Director, Cheil Worldwide (Samsung), South West Asia. Prior to that he was heading strategic planning for Publicis India.</p><p>Architected the 'Next is what' Samsung Mobile strategy to help the brand move from #4 to #2; Helped Maggi extend its franchise beyond convenience and children; Helped in transition of Andersen Consulting to Accenture.</p>");
		}
	});
	$("td.logo_link a img").hover(function()
	{
		this.src = this.src.replace("_inactive","_active");
	},
	function()
	{
		this.src = this.src.replace("_active","_inactive");
	});

	
});


function activateLink(buttonID)
{
	$(buttonID).addClass("active").siblings("li.active").removeClass("active");
}

function updateWhoareweContent(linkID)
{
	if(linkID == "#our_purpose")
		{
			$('#who-are-we').css("backgroundPosition"," center -1060px");
			$('div.whoarewe_content').html("<div class='our_purpose'><p>Support brands and businesses, <br/>that are at a point of change / entry, <br/>with marketing excellence to help <br/>realize their discontinuous <br/>growth goals.</p></div>");
		}
		else if(linkID == "#principles")
		{
			$('#who-are-we').css("backgroundPosition"," center -2060px");
			$('div.whoarewe_content').html("<div class='principles'><div class='principle_01'><h3>ENVISION</h3><p>Identify brand opportunities to be future ready </p></div><div class='principle_02'><h3>ENABLE</h3><p>Use proprietory tools, reapply best practices and <br/>coach marketing teams for sustained excellence</p></div><div class='principle_03'><h3>EXECUTE</h3><p>Develop executable plans to deliver strategy and <br/>innovations. Be accountable for results and ensure <br/>measurement and learning</p></div></div>");			
		}
		else if(linkID == "#values")
		{
			$('#who-are-we').css("backgroundPosition"," center -3060px");
			$('div.whoarewe_content').html("<div class='values'><div class='values_point'><h3>EXCELLENCE</h3><p>The pursuit of excellence drives us. Mere client delight is not enough </p></div><div class='values_point'><h3>INNOVATION</h3><p>We believe that if clients just wanted us to ratify their thinking, <br/>it would be a waste of their money and our time</p></div><div class='values_point'><h3>BUSINESS FIRST</h3><p>We may be working for a fee and not for a salary and we may <br/>be consultants from the outside, but we are on the same side of the table as you are</p></div><div class='values_point'><h3>TRANSPARENCY</h3><p>We are above-board in all our transactions and expect <br/>the same from our partners and clients</p></div><div class='values_point'><h3>ACCOUNTABILITY</h3><p>Non-negotiable! What we do for our clients has to deliver <br/>results and we are ready to put our money on this</p></div></div>");
		}
		else if(linkID == "#our_unique_proposition")
		{
			$('#who-are-we').css("backgroundPosition"," center -4060px");
			$('div.whoarewe_content').html("<div class='proposition'><p>Pedigreed and proven marketing <br/>and marketing services talent coming <br/>together to offer marketing advisory <br/>and execution capabilities.</p><p>Collectively, the leadership team has <br/>hands-on experience across Marketing <br/>Consulting, Strategic Planning, Media <br/>Planning, Media Research and <br/>Market Research. </p></div>");
		}		
		else if(linkID == "#our_work")
		{
			$('#who-are-we').css("backgroundPosition"," center -5060px");
			$('div.whoarewe_content').html("<div class='our_work'><div class='our_work_point'><h3>Consumer Centric Brand Strategy</h3><p>We worked with the world's leading Information Company to revamp its brand blueprint <br/>and in the process made significant changes to the product and helped evolve a <br/>robust consumer centric marketing strategy&nbsp;&nbsp;<img src='images/three_dots.gif' alt='...'/></p></div><div class='our_work_point'><h3>Bottom Line Focused Marketing Strategy</h3><p>In a category that is shallow on distribution, we helped evolve a category redefining pricing <br/>strategy that helped the brand  significantly broaden its distribution footprint&nbsp;&nbsp;<img src='images/three_dots.gif' alt='...'/></p></div><div class='our_work_point'><h3>The power of Innovation</h3><p>We helped a pioneer in modern retail, cutback its promotion costs by over 20% and <br/>increase the footfalls and revenues  by over 30%&nbsp;&nbsp;<img src='images/three_dots.gif' alt='...'/></p></div><div class='our_work_point'><h3>Marketing Leadership Outsourcing and <br/>Turnkey Project Management</h3><p>A British food MNC outsourced its marketing leadership to us and we helped <br/>it launch 6 new products in the ready-to-cook category in 8 months&nbsp;&nbsp;<img src='images/three_dots.gif' alt='...'/></p></div><div class='our_work_point'><h3>Workshops to build marketing competence</h3><p>We have deployed marketing competence building workshops for many leading <br/>MNC organisations, some of which have a marketing team over 30 people&nbsp;&nbsp;<img src='images/three_dots.gif' alt='...'/></p></div></div>");
		}
		else if(linkID == "#crystaleyes")
		{
			$('#who-are-we').css("backgroundPosition"," center -60px");
			$('div.whoarewe_content').html("<h3> OUR NAME ENCAPSULATES <br/>WHAT WE SEEK TO DO <br/>FOR OUR CLIENTS </h3><div class='our_name_desc'><ul><li class='point_01'>Crystallize <br/>insight into <br/>ideas</li><li class='point_02'>Crystallize <br/>ideas into <br/>execution</li><li class='point_03'>Crystallize <br/>the present <br/>to manage <br/>the future</li></ul></div></div>");
		}	
}

function updateOurTeamContent(linkID)
{
	if(linkID == "#collective_experience")
		{
			$('#our-team').css("backgroundPosition"," center -1000px");
			$('#our-team').css("backgroundColor","#ffffff");
			$('div#our-team div h2 img').attr('src', 'images/headings/experience_across_brands.gif');
			$('div.our_team_content').html("<div class='collective_experience'><img src='images/collective_experience_logo.gif' alt='Logo of collective experience of the directors' /></div>");
		}
		else if(linkID == "#our_partners")
		{
			$('#our-team').css("backgroundPosition"," center -2000px");
			$('#our-team').css("backgroundColor","#ffffff");
			$('div#our-team div h2 img').attr('src', 'images/headings/our_partners.gif');
			$('div.our_team_content').html("<div class='our_partners'><p>We have strong relationships across the marketing spectrum <br/>with advertising agencies, design agencies, <br/>BTL agencies, Digital agencies &amp; Media Agencies.</p><p>We can bring relevant agencies on board to provide end to <br/>end execution of projects led by us.</p></div>");			
		}
		else if(linkID == "#why_breif_us")
		{
			$('#our-team').css("backgroundPosition"," center -3000px");
			$('#our-team').css("backgroundColor","#DEDEDC");
			$('div#our-team div h2 img').attr('src', 'images/headings/why_brief_us.gif');
			$('div.our_team_content').html("<div class='why_brief_us'><p>Highly experienced and motivated team of marketeers.</p><p>Depth of experience across all facets of marketing.</p><p>Worked with top marketing brands across a host of industries.</p><p>Structured processes to understand issues and develop solutions.</p><p>Sharp, incisive proprietary tools that help build effective solutions.</p><p>Not just consultants: Ability to execute recommendations.</p><p>Work as an extension of client team and not as outsiders.</p></div>");
		}
		else if(linkID == "#team")
		{
			$('#our-team').css("backgroundPosition"," center top");
			$('#our-team').css("backgroundColor","#ffffff");
			$('div#our-team div h2 img').attr('src', 'images/headings/the_team.gif');
			$('div.our_team_content').html("<div class='director_profile'><h3 class='profile_name'>AMAR WADHWA <em style='font-size:12px;'>Founder &amp; Executive Director</em></h3><p>17 yrs of experience in brand strategy, consulting, research and media at Cheil Worldwide (Samsung), Publicis, BBDO, Accenture, Leo Burnett, IMRB.</p><p>Last Role – National Strategy Director, Cheil Worldwide (Samsung), South West Asia. Prior to that he was heading strategic planning for Publicis India.</p><p>Architected the 'Next is what' Samsung Mobile strategy to help the brand move from #4 to #2; Helped Maggi extend its franchise beyond convenience and children; Helped in transition of Andersen Consulting to Accenture.</p><p>We also have a very senior pool of consultants with vast experience <br/>in media, research, advertising and rural marketing, whom we engage, <br/> depending on the nature of projects.</p></div>");
			$('div.our_team_content div:last-child').css('paddingRight','0px');
		}		
}

function resetAllPages()
{
	  var linkID = $(this).attr("href");	
	  updateWhoareweContent("#crystaleyes");	  
	  updateOurTeamContent("#team");
	  $(".client_info").fadeOut("slow");
	  $(".logo_group").slideDown("slow");
	  $("div.description").hide();
	  $("div#accordion h3").removeClass("active");
	  $("div.meet_us_sec").show().siblings('div').hide();
	  activateLink($("ul.whoarewe_nav li:first-child"));
	  activateLink($("ul.our_team_nav li:first-child"));
	  activateLink($("ul.contact_nav li:first-child"));
}

