﻿String.prototype.contains = function(it) {
    return this.indexOf(it) != -1;
};

function initConsole() {
    console =
    {
        log: function(message) { },
        info: function(message) { },
        warn: function(message) { },
        error: function(message) {
            alert(message);
        },
        group:function(title) { },
        groupEnd:function() { }
    }
}
if (typeof (console) == 'undefined') initConsole();

function disqus_callback(){
    $('.dsq-comment-header-time a').each(function(){
		$(this).removeAttr('onclick').attr({href: 'javascript:void(0)'})
	})
	$('#dsq-popup-message').live('ready', function(){
		alert('ready')
	})
	$('#dsq-post-button').click(function(){
		
	})
}
var tabs = [0, 185, 315];
var clickIndex = 0;
// JavaScript Document
$(document).ready(function(){
    $('table.zebra tr:odd').addClass('odd')
    $('div.big-item div.params p:even').addClass('odd')
    $('div.big-item div.params div.left:not(:last)').each(function(){
        $(this).children('p:odd').css({
            borderRight: '#fff 1px solid'
        })
    })
    $('div.comment:last').css({
        border: 'none'
    })
    $('div.comment div.text:odd').addClass('odd')
    $('div.tabs a').click(function(){
        $('div.tabs a').removeAttr('style')
        $(this).next('a').css({
            borderLeft: 'none'
        })
        $(this).addClass('active').siblings('a').removeClass('active').removeClass('rc3')
        var tab = $('div.tabs a').index(this)
        $('div.tab-content').eq(tab).addClass('active').siblings('div.tab-content').removeClass('active')
		scrolToTab(tab)
    })
    $('#scrollable').scrollable({
        size:3,
        clickable: false
    })
	$('#tab-scroller a.next').click(function(){
		console.log(clickIndex,tabs.length-1,clickIndex >= tabs.length-1)
		if(clickIndex >= tabs.length-1) return false;
		clickIndex++;
		$('div.tabs div.items').animate({left: -tabs[clickIndex]+'px'}, 300)
		if(clickIndex > 0){
			$('#tab-scroller a.prev').removeClass('disabled')
		}
		if(clickIndex >= tabs.length-1){
			$('#tab-scroller a.next').addClass('disabled')
		}
	})
	$('#tab-scroller a.prev').click(function(){
		if(clickIndex == 0) return false;
		clickIndex--;
		console.log(tabs[clickIndex])
		$('div.tabs div.items').animate({left: -1*tabs[clickIndex]+'px'}, 300)
		if(clickIndex < tabs.length-1){
			$('#tab-scroller a.next').removeClass('disabled')
		}
		if(clickIndex == 0){
			$('#tab-scroller a.prev').addClass('disabled')
		}
	})
	$('#tab-scroller a.prev').addClass('disabled')
    $('div.tabs a.active').next('a').css({
        borderLeft: 'none'
    })
    $('#scrollable div.item a').click(function(){
        var bigInfo = $('#scrollable div.item a').index(this)
        $('#big-items div.big').eq(bigInfo).fadeIn(300).siblings('div.big').fadeOut(300)
    })
    $('#main-menu ul li').hover(
        function(){
            $(this).children('ul').slideDown(300);
        },
        function(){
            $(this).children('ul').slideUp(300);
        });
    //	$('ul.categories:first').slideDown(0)
    //	$('ul.categories:last').addClass('last')
    //	$('div.section:first').addClass('rc3')
	if($('ul.categories.active').size() == 0){
		$('ul.categories').slideDown(0).addClass('active')
		$('div.section').addClass('rc3 active')
	}
    $('ul.categories.active').slideDown(0)
    $('ul.categories:last').addClass('last')
    $('div.section.active').addClass('rc3')

    $('div.section').click(function(){
        $(this).toggleClass('rc3').siblings('div.section').removeClass('rc3')
        $(this).next('ul.categories').slideToggle(300).siblings('ul.categories').slideUp(300)
    })
	
    $('div.thumbs').jScrollPane({
        showArrows: false,
        scrollbarMargin: 15,
        scrollbarWidth: 2,
        dragMaxHeight: 25
    }).mousewheel()
	$('a.iframe').click(function(){
		$('body').append('<div id="frame" class="rc3"><div class="head">'+$(this).attr('title')+'<a href="javascript:deleteFrame()"><img alt="" src="/images/close.png"></a></div><iframe frameborder="0" width="658px" height="500" class="pop" src="'+$(this).attr('href')+'"></iframe></div>').fadeIn(300)
		$('#shadow').fadeIn(300)
		return false
	})
	
	
	 $('div.sort>span>a').click(function () {
        $(this).next('ul').slideDown(200)
        $(this).parent('span').mouseleave(function () {
            $(this).children('ul').slideUp(200)
        })
    })
	
	
});
$(window).load(function(){
});
function scrolToTab(tabIndex){
	console.log(tabIndex);
	switch(tabIndex){
		case 3: 
			index = 1; 
			clickIndex = 1;
			$('#tab-scroller a.next').removeClass('disabled')
			$('#tab-scroller a.prev').removeClass('disabled')
			break;
		case 4: 
		case 5: 
			index = 2; 
			clickIndex = 2;
			$('#tab-scroller a.next').addClass('disabled')
			$('#tab-scroller a.prev').removeClass('disabled')
			break;
		default: 
			index = 0 ;
			clickIndex = 0;
			$('#tab-scroller a.next').removeClass('disabled')
			$('#tab-scroller a.prev').addClass('disabled')
		break;
	}
	$('div.tabs div.items').animate({left: -tabs[index]+'px'}, 300)
}
function deleteFrame(){
	$('#shadow').fadeOut(300)
	$('#frame').fadeOut(300).remove()
}
function showRequestSender(){
    $('#sendrequest').fadeIn(300)
}
function hideRequestSender(){
    $('#sendrequest').fadeOut(300)
}
function showProposeSender(){
    $('#sendpropose').fadeIn(300)
}
function hideProposeSender(){
    $('#sendpropose').fadeOut(300)
}
function showCallmeSender(){
    $('#sendcallme').fadeIn(300)
}
function hideCallmeSender(){
    $('#sendcallme').fadeOut(300)
}
function showTab(estate_name){
    var el = $('div.tabs a').filter(function() {
        return this.text == estate_name;
    });
	
    if(el.length==0)return false;
    else el = el.eq(0);
    $('div.tabs a').removeAttr('style')
    $(el).next('a').css({
        borderLeft: 'none'
    })
    $(el).addClass('active').siblings('a').removeClass('active').removeClass('rc3')
    var tab = $('div.tabs a').index(el)
	scrolToTab(tab)
    $('div.tab-content').eq(tab).addClass('active').siblings('div.tab-content').removeClass('active')
    return true;
}




