// <summary>
// Global function calls
// </summary>
function executeHandler(){
pngFix();
animateScroll();
GB_ANIMATION = true;
signUp();
getNews();
$('#GB_overlay').height($('#master').height());
$(".alt").hide();
newsletterclick();
handlePopup();
}

// <summary>
// navigaton scroll animations
// </summary>
function animateScroll()
{
 $(".navigation>ul").children().each(function(){
  $(this).click(function(){
   $.scrollTo( '#'+$(this).find("a").attr("rel"), 400, { easing:'easeout' });
   

   
  });
 });
 

 
// <summary>
// hover animations
// </summary>

 $("#signUp").hover(
 function(){
 $(this).fadeTo("slow",0.6);
 },
 function(){
 $(this).fadeTo("slow",1);
 }
 );
 
 $("#contactUs").hover(
 function(){
 $(this).fadeTo("slow",0.6);
 },
 function(){
 $(this).fadeTo("slow",1);
 }
 );
}

// <summary>
// handling popuo window for privacy policy
// </summary>
function handlePopup()
{
 $("#Footer a").click(function(){
 $("#PopupWindow").css({left:$("#contactSection .copy").offset().left+"px",top:$("#contactSection .copy").offset().top+250+"px"});
 if ($(this).attr("rel") == "privacy policy")
 {
  $("#PopupWindow").css({height:"350px"});
  $("#PopupWindow").show();
  $("#PopupWindow .copy").html("");
  $.ajax({
   type: "GET",
   url: "PrivacyPolicy.html",
   dataType: "html",
   success: function(data) {
   $("#PopupWindow .copy").html(data);
   $.scrollTo( '#PopupWindow', 1000, { easing:'easeout' });
   }
  }); //close $.ajax( 
 }
 if ($(this).attr("title") == "disclaimer")
 {
  $("#PopupWindow").css({height:"250px"});
  $("#PopupWindow").show();
  $("#PopupWindow .copy").html("");
  $.ajax({
   type: "GET",
   url: "Disclaimer.html",
   dataType: "html",
   success: function(data) {
   $("#PopupWindow .copy").html(data);
   }
  }); //close $.ajax(  
 }
 return false;
 });
}

// apply to all png images 
function pngFix(){
$('img[@src$=.png]').ifixpng(); 
}


// <summary>
//  This function to assign target blank to the external link. html target blank is not a standard w3c validated code. insted of using target="_blank" we use rel="external" and replace the rel with javascript.
// </summary>
function AssignLinks() 
{
	$("a[rel='external']").attr("target","_blank");
	$("a[href='#']").click(function(){
		return false;
	});
}

// <summary>
//  This function to attach non-ie css selectors to the html elements
// </summary>
function AssignCSSSelectors()
{
	if(jQuery.browser.msie)
	{
		$("li:first-child").addClass("FirstChild");
		$("li:last-child").addClass("LastChild");
		$("td:last").addClass("LastChild");
  $("tr:first").addClass("FirstChild");
	}
}

// <summary>
//  attaching gray box
// </summary>
function attachGraybox(linkObj)
{
 var t ="";
 //var t = linkObj.title || linkObj.innerHTML || linkObj.href;
 GB_show(t,linkObj,470,600);
 return false;
}

/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;

function GB_show(caption, url, height, width,parentId,urltype) {
	try {
  GB_HEIGHT = height || 400;
  GB_WIDTH = width || 400;
  if(!GB_DONE) {
    $("#GB_window img").click(GB_hide);
    $("#GB_overlay").click(GB_hide);
    $(window).resize(GB_position(parentId));
    GB_DONE = true;
  }
  $("#GB_frame").remove();
  $("#GB_image").remove();
  if (urltype=="external")
  {
   $("#GB_window").append("<iframe frameborder='0' scrolling='no' id='GB_frame' src='"+url+"'></iframe>");
  }
  else
  {
  $("#GB_window").append("<img src='"+ url+"' id ='GB_image' width='860' height='406' />");
  }

  $("#GB_caption").html(caption);
  $("#GB_overlay").show();
  $("#GB_window").show();
  $('embed, object, select').css({ 'display' : 'none' });
  $('h1,h2').css({ 'display' : 'none' });
  $(".navigation").css({ 'display' : 'none' });
  GB_position(parentId);

  if(GB_ANIMATION)
    $("#GB_window").slideDown("slow");
  else
    $("#GB_window").show();
	} catch(e) {
		alert( e );
	}
}

function GB_hide() {
  $("#GB_window,#GB_overlay").hide();
  $('embed, object, select').css({ 'display' : 'block' });
  $('h1,h2').css({ 'display' : 'block' });
  $(".navigation").css({ 'display' : 'block' });
}


function GB_position(parent) {
  var de = document.documentElement;
  var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	 $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",left: ((w - GB_WIDTH)/2)+"px" });
  //$("#GB_frame").css("height",GB_HEIGHT - 32 +"px");
  //$("#GB_window").css({top: $(parent).offset().top + 120+ "px",left: ((w - GB_WIDTH)/2)+"px"});
  $("#GB_window").css({top: $(parent).offset().top + 120+ "px",left: ((w - GB_WIDTH)/2)+"px"});
  $.scrollTo( '#GB_window', 500, { easing:'easeout' });
}

function signUp()
{
 $(".signupButton1").click(function(){
  $("#signUp").fadeOut("fast",
   function(){
    $("#signupForm").fadeIn("fast");
   });
   return false;
 });
}


// <summary>
//  parsing news
// </summary>

//  Reading news from xml file
// </summary>
function getPortfolioImages(xmlFile)
{
var html = "<div id='gallery'>";
$.ajax({
 type: "GET",
 url: xmlFile,
 dataType: "xml",
 success: function(xml) {
  $(xml).find('image').each(function(){
  html = html + '<a href="'+ $(this).attr("image") + '" title="' + $(this).attr("title") + '"></a>';
  }); //close each(
  html = html + "</div>";
  $(html).find("a").lightBox();
 }
}); //close $.ajax(
}

function showImage(ImgSrc)
{
 getPortfolioImages(ImgSrc)
}

// <summary>
//  These functions handle events generated by an Input Text box
// </summary>

function InputTextOnFocusHandler (InputTag, DefaultText)
{
	try
	{  		
		if (InputTag.value == DefaultText)
		{
			InputTag.value = "";
		}
	}
	catch (ExceptionObject)
	{
	}
}

function InputTextOnBlurHandler (InputTag, DefaultText)
{
	try
	{
		if (InputTag.value == "")
		{
			InputTag.value = DefaultText;	
		}
	}
	catch (ExceptionObject)
	{
	}
}

// <summary>
//  Newsletter subscription ajax functionalities
// </summary>
function newsletterclick()
{
 $(".signupButton2").click(function(){
  var emailVal = $("#emailtext").attr("value");
  var ajxURL= "newsletter.aspx?email=" + emailVal;
  if ((emailVal==""))
  {
   alert ("Please fill in your email");
   return false;
  }
  
  if (!validEmail(emailVal))
  {
   return false;
  }

  $.ajax({
  type: "GET",
  url: ajxURL,
  success: function(msg){
   $("#signupForm fieldset").hide();
   $("#signupForm").html("<p style='width:150px;font-size:11px;color:333;padding:40px 20px 40px 50px;'>" + msg + "</p>");
  }
  });
  return false;
 });
}

// <summary>
//  Email validation functions
// </summary>
function validEmail(email) {
		var at="@";
		var dot=".";
		var lat=email.indexOf(at);
		var lstr=email.length;
		var ldot=email.indexOf(dot);
		if (email.indexOf(at)==-1){
		   alert ("Please fill in a valid email");
		   return false;
		}

		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   return false;
		}

		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr){
		    alert ("Please fill in a valid email");
		    return false;
		}

		 if (email.indexOf(at,(lat+1))!=-1){
		    alert ("Please fill in a valid email");
		    return false;
		 }

		 if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot){
		    alert ("Please fill in a valid email");
		    return false;
		 }

		 if (email.indexOf(dot,(lat+2))==-1){
		    alert ("Please fill in a valid email");
		    return false;
		 }
		
		 if (email.indexOf(" ")!=-1){
		    alert ("Please fill in a valid email");
		    return false;
		 }
 		 return true;
	}
