$(document).ready(function(){
	smartRollover();
	if(document.getElementById("tab-resource")){
		tabui();
	}
	pageScroll('.to-top','#container');
	pageScroll('.footer-bnr li.last','#container');
	if(document.getElementById("tracker")){
		$("#tracker").liScroll(); 
	}
	navReplace();
});


function smartRollover() {  
	if(document.getElementsByTagName) {  
		var images = document.getElementsByTagName("img");  
			for(var i=0; i < images.length; i++) {  
				if(images[i].getAttribute("src").match("_off.")){  
					images[i].onmouseover = function() {  
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));  
				}  
				images[i].onmouseout = function() {  
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));  
				}  
			}  
		}  
	}  
}

function pageScroll(trg,target){
    $(trg).click(function () {
        $(this).blur();
        $('html,body').animate({ scrollTop: $(target).offset().top }, 'fast');
        return false;
    });
}
/*nav replace*/
var navReplace = function(){
	var loc = location.href;
	if(loc.indexOf("/vacancy/") != -1){
		var set = $("#nav img:eq(0)").attr("src").replace("_off.", "_on.");
		$("#nav img:eq(0)").attr("src",set);
	}
	if(loc.indexOf("/property/") != -1){
		var set = $("#nav img:eq(1)").attr("src").replace("_off.", "_on.");
		$("#nav img:eq(1)").attr("src",set);
	}
	if(loc.indexOf("/area/") != -1){
		var set = $("#nav img:eq(2)").attr("src").replace("_off.", "_on.");
		$("#nav img:eq(2)").attr("src",set);
	}
	if(loc.indexOf("/particular/") != -1){
		var set = $("#nav img:eq(3)").attr("src").replace("_off.", "_on.");
		$("#nav img:eq(3)").attr("src",set);
	}
}
//tab
var tabui = function(){
	$("#tab-resource .tab-sec").hide();
	var index;
	if(document.getElementById("tabindex")) {
		index = parseInt(document.getElementById("tabindex").value);
	} else {
		index = 0;
	}
	if (index == 1) {
		$("#tab-resource .tab-sec:eq(1)").show();
		$('#tab-nav li:eq(2) a').addClass('on');
	} else if (index == 2) {
		$("#tab-resource .tab-sec:eq(2)").show();
		$('#tab-nav li:eq(3) a').addClass('on');
	} else {
		$("#tab-resource .tab-sec:eq(0)").show();
		$('#tab-nav li:eq(1) a').addClass('on');
	}
	
	$("#tab-nav li a").click(function(){
		var id = $(this).attr("href");
		$("#tab-resource > .tab-sec").css('display','none');
		$(id).fadeIn('first');
		$("#tab-resource > .tab-sec").not(id).css('display','none');
		$('#tab-nav li a').removeClass('on');
		$(this).addClass('on');
		return false;
	});
}

var scrollText = {};
scrollText.num = 0;
scrollText.interval = 0;
scrollText.unitOffW = 0;
scrollText.offW = 0;

scrollText.init = function(){
	$("#tracker").css("position","relative");
	$("#tracker").css("overflow","hidden");
	$("#tracker p").css("position","absolute");
	$("#tracker p").css("right","0");
	
	scrollText.unitOffW = $("#tracker").width();
	scrollText.offW = $("#tracker p").width();
	var offH = $("#tracker p").height();
	$("#tracker").css("height",offH+"px");
	
	scrollText.interval = setInterval(scrollText.move,100);
}

scrollText.move = function(){
	/*$("#tracker p").stop(true , false).animate(
    {left: -100}, 2000
	);*/
	
	/*var cpos = $("#tracker p").css("left");
	document.getElementById("beta-block").innerHTML = cpos + "::"+new Number(scrollText.offW)+new Number(scrollText.unitOffW);
	if(cpos <= scrollText.offW+scrollText.unitOffW){
		$("#tracker p").css("right",scrollText.num+"px");
		scrollText.num += 5;
	}*/
}

/*!
 * liScroll 1.0
 * Examples and documentation at: 
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2 (30-MARCH-2009)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 * 
 */


jQuery.fn.liScroll = function(settings) {
		settings = jQuery.extend({
		travelocity: 0.07
		}, settings);		
		return this.each(function(){
				var $strip = jQuery(this);
				$strip.addClass("newsticker")
				var stripWidth = 0;
				var $mask = $strip.wrap("<div class='mask'></div>");
				var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
				var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
				$strip.find("li").each(function(i){
				stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar
				});
				$strip.width(stripWidth);			
				var totalTravel = stripWidth+containerWidth;
				var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
				function scrollnews(spazio, tempo){
				$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
				}
				scrollnews(totalTravel, defTiming);				
				$strip.hover(function(){
				jQuery(this).stop();
				},
				function(){
				var offset = jQuery(this).offset();
				var residualSpace = offset.left + stripWidth;
				var residualTime = residualSpace/settings.travelocity;
				scrollnews(residualSpace, residualTime);
				});			
		});	
};
