$(function(){
	
	// load our flash movies for tools nav
	var peopleText = $('#peopleLink').text();
	$('#peopleFlash').flash({
		swf: '/dtzir/templates_dtzir/assets/flash/search_people.swf',
		width: '75',
		height: '89',
		id: 'propertyFlashMovie',
		expressInstaller: 'expressInstall.swf',
		params: {
			wmode: 'transparent',
			flashvars: {
				title_text: peopleText
			}
		}
	});
	var marketsText = $('#marketsLink').text();
	$('#marketsFlash').flash({
		swf: '/dtzir/templates_dtzir/assets/flash/search_markets.swf',
		width: '75',
		height: '89',
		id: 'marketsFlashMovie',
		expressInstaller: 'expressInstall.swf',
		params: {
			wmode: 'transparent',
			flashvars: {
				title_text: marketsText
			}
		}
	});	
	var reportsText = $('#reportsLink').text();
	$('#reportsFlash').flash({
		swf: '/dtzir/templates_dtzir/assets/flash/search_reports.swf',
		width: '75',
		height: '89',
		id: 'reportsFlashMovie',
		expressInstaller: 'expressInstall.swf',
		params: {
			wmode: 'transparent',
			flashvars: {
				title_text: reportsText
			}
		}
	});
	var propertyText = $('#propertyLink').text();
	$('#propertyFlash').flash({
		swf: '/dtzir/templates_dtzir/assets/flash/search_property.swf',
		width: '75',
		height: '89',
		id: 'propertyFlashMovie',
		expressInstaller: 'expressInstall.swf',
		params: {
			wmode: 'transparent',
			flashvars: {
				title_text: propertyText
			}
		}
	});
	// this adds click functionality to links in case the flash is not loaded
	$('a#peopleLink').click(function(){
		// call click event
		people_click();
	});
	$('a#marketsLink').click(function(){
		// call click event
		markets_click();
	});
	$('a#reportsLink').click(function(){
		// call click event
		reports_click();
	});	
	$('a#propertyLink').click(function(){
		// call click event
		property_click();
	});	
	// close links - ensure that all tool boxes are closed
	$("#close1, #close2, #close3, #close4").click(function(){	
		$('#searchTools1').hide();
		$("#searchTools2").hide();
		$("#searchTools3").hide();
		$("#searchTools4").hide();
	});
});

// these functions are called from flash icons
function property_click(){
	$(function(){
		$("#searchTools1").hide();
		$("#searchTools2").hide();
		$("#searchTools3").hide();
		$('#searchTools4').slideToggle();
	});
}
function people_click(){
	$(function(){
		$('#searchTools2').hide();
		$("#searchTools3").hide();
		$("#searchTools4").hide();
		$('#searchTools1').slideToggle();
	});
}
function reports_click(){
	$(function(){
		$('#searchTools1').hide();
		$("#searchTools3").hide();
		$("#searchTools4").hide();
		$('#searchTools2').slideToggle();
	});
}
function markets_click(){
	$(function(){
		$('#searchTools1').hide();
		$("#searchTools2").hide();
		$("#searchTools4").hide();
		$('#searchTools3').slideToggle();
	});
}


//define our sifr fonts

if(typeof sIFR == "function"){

	sIFR.replaceElement(named({sSelector:"body#default #homeKeyMsgs h2, body#lightgrey-on-dkdove #homeKeyMsgs h2, #mCol h1", sFlashSrc:"/dtzir/templates_dtzir/assets/flash/helveticaneuelight.swf", sColor:"#ff0033",  sWmode:"transparent"}));
	
	sIFR.replaceElement(named({sSelector:"body#dove-on-black #homeKeyMsgs h2, body#grey-on-black #homeKeyMsgs h2, body#grey-on-dkgrey #homeKeyMsgs h2", 
	sFlashSrc:"/dtzir/templates_dtzir/assets/flash/helveticaneuelight.swf", sColor:"#FFFFFF",  sWmode:"transparent"}));
	
	sIFR.replaceElement(named({sSelector:"body#default #searchTools h2", 
	sFlashSrc:"/dtzir/templates_dtzir/assets/flash/helveticaneuelight.swf", sColor:"#FFFFFF",  sWmode:"transparent", sFlashVars:"textalign=center"}));
	
	sIFR.replaceElement(named({sSelector:"body#dove-on-black #searchTools h2, body#lightgrey-on-dkdove #searchTools h2", sFlashSrc:"/dtzir/templates_dtzir/assets/flash/helveticaneuelight.swf", sColor:"#2a2f39",  sWmode:"transparent", sFlashVars:"textalign=center"}));
	
	sIFR.replaceElement(named({sSelector:"body#grey-on-black #searchTools h2, body#grey-on-dkgrey #searchTools h2", sFlashSrc:"/dtzir/templates_dtzir/assets/flash/helveticaneuelight.swf", sColor:"#333333",  sWmode:"transparent", sFlashVars:"textalign=center"}));	

};

//global jquery
$(document).ready(function(){
    
	//define our rollovers for the global tools nav (hide & show flash)
	/*$(".trigger").hover(
	      function () {
	        $(this).children(".flashFrameImg").removeClass("flashFrameImg").addClass("hide");
			$(this).children("#propertyFlash, #peopleFlash, #reportsFlash, #marketsFlash").addClass("show");
	      }, 
	      function () {
	        $(this).children(".hide").removeClass("hide").addClass("flashFrameImg");
			$(this).children("#propertyFlash, #peopleFlash, #reportsFlash, #marketsFlash").removeClass("show");
	      }
	    );*/
	
	//trigger signInPanel
	$("#login").click(function () {
	      $("#signInPanel").toggleClass("hidden");
	    });
	
	$("#closeLogin").click(function () {
		$("#signInPanel").addClass("hidden");
	});
	
	//trigger language panel 
		$("#selectLang").click(function () {
	      $("ul#langs").toggleClass("hidden");
	    });
	
	$("#mainNav, #banner-tools").mouseover(function () {
		$("ul#langs").addClass("hidden");
	});
	
	//theme testing
	/*$("#default-theme").click(function () {
		
		$("body").attr({ 
	          id: "default",
	         
	        });
	});
	$("#dove-on-black-theme").click(function () {
		$("body").attr({ 
	          id: "dove-on-black",
	         
	        });
	});
	
	$("#grey-on-black-theme").click(function () {
		$("body").attr({ 
	          id: "grey-on-black",
	         
	        });
	});
	
	$("#grey-on-dkgrey-theme").click(function () {
		$("body").attr({ 
	          id: "grey-on-dkgrey",
	         
	        });
	});
	
	$("#lightgrey-on-dkdove-theme").click(function () {
		$("body").attr({ 
	          id: "lightgrey-on-dkdove",
	         
	        });
	});*/
	
	/* --TCS code begins here --*/
	/* --CR updates begin --*/
	$("#selectCountry").click(function () {
		$("ul#countries").toggleClass("hidden");
	    });
	//sliding panel function added by tcs
	//initially hiding the div

	$("#searchTools1").addClass("hidden");
	$("#searchTools2").addClass("hidden");
	$("#searchTools3").addClass("hidden");
	$("#searchTools4").addClass("hidden");
	$("#sp1").addClass("hidden");
	$("#sp2").addClass("hidden");
	$("#sp3").addClass("hidden");
	


	$("#searchTools1").hide();
	$("#searchTools2").hide();
	$("#searchTools3").hide();
	$("#searchTools4").hide();
	

	
	$("ul li#propLi").click(function () {
		$("#searchTools1").hide();
		$("#searchTools2").hide();
		$("#searchTools3").hide();
		$("#searchTools4").slideToggle("slow");
		$(this).toggleClass("active");
	
	});

/*$("ul li a#abc").click(function () {
		alert("inside ..");
		
	
	});*/


	$("#close4").click(function () {
		$("#searchTools4").hide();
	});

	$("ul li#peopleLi").click(function () {
		$("#searchTools4").hide();
		$("#searchTools2").hide();
		$("#searchTools3").hide();
		$("#searchTools1").slideToggle("slow");
		$(this).toggleClass("active");
	
	});
	$("#close1").click(function () {
		$("#searchTools1").hide();
	});
	/* -- Report --*/
	$("ul li#reportLi").click(function () {
		$("#searchTools1").hide();
		$("#searchTools3").hide();
		$("#searchTools4").hide();
		$("#searchTools2").slideToggle("slow");
		$(this).toggleClass("active");
	
	});

	$("#close2").click(function () {
		$("#searchTools2").hide();
	});
	
	$("ul li#marketLi").click(function () {
		$("#searchTools1").hide(); // hiding the already opened people search tool slider
		$("#searchTools2").hide(); // hiding the already opened report search tool slider
		$("#searchTools4").hide();
		$("#searchTools3").slideToggle("slow"); //opening the property search tool slider
	$(this).toggleClass("active");	
	});

	$("#close3").click(function () {
		$("#searchTools3").hide();
	});


	$("#sp4").click(function () {
        $("#sp1").animate({
            "width": "toggle"
            }, { duration: "slow" });
    });
	$("#sp5").click(function () {
        $("#sp2").animate({
            "width": "toggle"
            }, { duration: "slow" });
    });
    $("#sp6").click(function () {
        $("#sp3").animate({
            "width": "toggle"
            }, { duration: "slow" });
    });
    
	/* --CR updates end --*/
	/* --TCS code ends here --*/


});

//resize fonts

function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A--' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A++');
      break;
    case 'A++' :
      break;
    default :
      setActiveStyleSheet('A');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'A++' : 
      setActiveStyleSheet('A+');
      break;
    case 'A+' : 
      setActiveStyleSheet('A');
      break;
    case 'A' : 
      setActiveStyleSheet('A-');
      break;
    case 'A-' : 
      setActiveStyleSheet('A--');
      break;
    case 'A--' : 
       break;
    default :
      setActiveStyleSheet('A--');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('A');
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);