var imgUrl = "http://resources.dev.most.ua/specific/horo/img/zodiac/";
$(document).ready(function() {
	$('.png').each(function(){
		$(this).parent().pngFix();
	});
	// Fix blue boxes height on index
	$('#fixh_1_1, #fixh_1_2').height(Math.max($('#fixh_1_1').height(), $('#fixh_1_2').height()));
	$('#fixh_2_1, #fixh_2_2').height(Math.max($('#fixh_2_1').height(), $('#fixh_2_2').height()));
	$('#fixh_3_1, #fixh_3_2').height(Math.max($('#fixh_3_1').height(), $('#fixh_3_2').height()));
	
	// Navigate though tabs "Gadanie, Talisman, Tests"
	$('#horo_links_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_links_tabs li').removeClass('current');
			$('#horo_links_tabs li:eq(' + index + ')').addClass('current');
			$('#horo_links > .b_text').hide();
			$('#horo_links > .b_text:eq(' + index + ')').show();
			e.preventDefault();
		});
	});

	// Navigate though tabs "Зодиакальный/Китайский"
	$('#horo_types_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_types_tabs li').removeClass('current');
			$('#horo_types_tabs li:eq(' + index + ')').addClass('current');
			$('#horo_types > .b_text').hide();
			$('#horo_types > .b_text:eq(' + index + ')').show();

			e.preventDefault();
		});
	});

	// Navigate though tabs "На сегодня/неделю/месяц/год"
	$('#horo_time_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_time_tabs li').removeClass('current');
			$('#horo_time_tabs li:eq(' + index + ')').addClass('current');
			clickTab1($(this).attr('signKey'), $(this).attr('signType'));
			e.preventDefault();
		});
	});

	//Navigate though tabs on Horoscope/Index

$('#horo_time_tabs12 a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_time_tabs12 li').removeClass('current');
			$('#horo_time_tabs12 li:eq(' + index + ')').addClass('current');
			clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
			e.preventDefault();
		});
	});
$('#horo_time_tabs1 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs1 li').removeClass('current');
        $('#horo_time_tabs1 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs2 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs2 li').removeClass('current');
        $('#horo_time_tabs2 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs3 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs3 li').removeClass('current');
        $('#horo_time_tabs3 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs4 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs4 li').removeClass('current');
        $('#horo_time_tabs4 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs5 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs5 li').removeClass('current');
        $('#horo_time_tabs5 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs6 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs6 li').removeClass('current');
        $('#horo_time_tabs6 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs7 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs7 li').removeClass('current');
        $('#horo_time_tabs7 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs8 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs8 li').removeClass('current');
        $('#horo_time_tabs8 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs9 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs9 li').removeClass('current');
        $('#horo_time_tabs9 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs10 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs10 li').removeClass('current');
        $('#horo_time_tabs10 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});
$('#horo_time_tabs11 a').each(function(index) {
    $(this).click(function(e) {
        $('#horo_time_tabs11 li').removeClass('current');
        $('#horo_time_tabs11 li:eq(' + index + ')').addClass('current');
        clickTabType4($(this).attr('signKey'), $(this).attr('signType'), $(this).attr('signName'));
        e.preventDefault();
    });
});







	// Navigate though tabs "Лунный календарь/Здоровье/Эротический/Детский"
	$('#horo_type_1_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_type_1_tabs li').removeClass('current');
			$('#horo_type_1_tabs li:eq(' + index + ')').addClass('current');
			clickTabType1($(this).attr('signKey'), $(this).attr('signType'));
			e.preventDefault();
		});
	});

	// Navigate though tabs "Бизнес/Путешествия/Покупки"
	$('#horo_type_2_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#horo_type_2_tabs li').removeClass('current');
			$('#horo_type_2_tabs li:eq(' + index + ')').addClass('current');
			clickTabType2($(this).attr('signKey'), $(this).attr('signType'));
			e.preventDefault();
		});
	});

	// Navigate though tabs 'совместимость'
	$('#compatibility_tabs a').each(function(index) {
		$(this).click(function(e) {
			$('#compatibility_tabs li').removeClass('current');
			$('#compatibility_tabs li:eq(' + index + ')').addClass('current');
			$('#compatibility_tab > .b_text').hide();
			$('#compatibility_tab > .b_text:eq(' + index + ')').show();
			e.preventDefault();
		});
	});

	$('#zodiaks_dd li a').click(selectZodiak);
/*
	$('#horo_time_tabs a').each(function(index) {
		$(this).click(function(e) {
			clickTab(index);
			e.preventDefault();
		})
	});
*/
});

function clickTab1(signKey, signType) {
	$.getJSON('/Horoscope/GetZodiacHoro/' + signKey + '/' + signType, function(data) {
		$('#zodiaks_period').text(data.Period);
		$('#zodiaks_text').empty();
		$('#zodiaks_text').append(data.Horo.HoroscopeData);
		$('#zodiaks_title').text(data.Title);
		$('#zodiaks_type_moreLink').attr("href", window.location.pathname + "/" + signKey);
	});
	Header.HideAllTitleItemBlocks();
};

function clickTabType1(signKey, signType) {
	$.getJSON('/Horoscope/GetZodiacHoro/' + signKey + '/' + signType, function(data) {
		$('#zodiaks_type1_period').text(data.Period);
		$('#zodiaks_type1_text').empty();
		$('#zodiaks_type1_text').append(data.Horo.HoroscopeData);
		$('#zodiaks_type1_title').text(data.Title);
		$('#zodiaks_type1_moreLink').attr("href", window.location.pathname + "/" + signKey);
	});
	Header.HideAllTitleItemBlocks();
};

function clickTabType2(signKey, signType) {
	$.getJSON('/Horoscope/GetZodiacHoro/' + signKey + '/' + signType, function(data) {
		$('#zodiaks_type2_period').text(data.Period);
		$('#zodiaks_type2_text').empty();
		$('#zodiaks_type2_text').append(data.Horo.HoroscopeData);
		$('#zodiaks_type2_title').text(data.Title);
		$('#zodiaks_type2_moreLink').attr("href", window.location.pathname + "/" + signKey);
	});
	Header.HideAllTitleItemBlocks();
};



function clickTabType4(signKey, signType, singName) {
    $.getJSON('/Horoscope/GetZodiacHoro/' + signKey + '/' + signType, function(data) {
        $('#zodiaks_period' + signType).text(data.Period);
        $('#zodiaks_text' + signType).empty();
        $('#zodiaks_text' + signType).append(data.Horo.HoroscopeData);
        $('#zodiaks_title' + signType).text(data.Title);
        $('#zodiaks_moreLink' + signType).attr("href", "Zodiac/" + singName + "/" + signKey);
    });
	Header.HideAllTitleItemBlocks();
};




function selectZodiak(e) {
	var signKey = $(this).parent().attr('signKey');
	var el = this;
	$.getJSON('/Horoscope/GetDailyZodiacHoro/' + signKey, function(data) {
		$(el).parent().parent().children('li').removeClass('current');
		$(el).parent().addClass('current');
		$('.zodiaks_dd').text($(el).text());
		$('#zodiaks_period').text(data.SignPeriod);
		$('#zodiaks_img').attr("src", imgUrl + data.SignNameEng + "_48.png");
		$('#zodiaks_url').attr("href", data.PageUrl);
		$('#zodiaks_text').text(data.Horo.HoroscopeData + '..');
	});
	Header.HideAllTitleItemBlocks();
	e.preventDefault();
};

function ddlOnChange(el) {
	var signKey = $(el).val();
	var el = this;
	$.getJSON('/Horoscope/GetChinaHoro/' + signKey, function(data) {
		$('#china_horo_years').text(data.SignYears);
		$('#china_horo_name').text(data.SignName);
		$('#china_horo_data').text(data.Data);
		$('#china_horo_url').attr("href", data.Url);
	});
	Header.HideAllTitleItemBlocks();
	e.preventDefault();
};

function DisplayHoroDayCompatibility() {
	$('#Compatibility_Horo_Data').hide();
	if ($('#SexSecond').attr("value") != "0" &&
		$('#SexFirst').attr("value") != "0" &&
		$('#HoroFirst').attr("value") != "0" &&
		$('#HoroSecond').attr("value") != "0") {
		if ($('#SexFirst').attr("value") == 1) {
		    this.location.href = '/Compatibility/' +
					$('#HoroFirst').attr("value") + '/' +
					$('#HoroSecond').attr("value") + '/Day';
			
		}
		else if ($('#SexFirst').attr("value") == 2) {
		this.location.href = '/Compatibility/' +
						$('#HoroSecond').attr("value") + '/' +
						$('#HoroFirst').attr("value") + '/Day';
		
		}
		Header.HideAllTitleItemBlocks();
	}
}

function DisplayHoroCompatibility() {
	$('#Compatibility_Horo_Data').hide();
	if ($('#SexSecondTotal').attr("value") != "0" &&
		$('#SexFirstTotal').attr("value") != "0" &&
		$('#HoroFirstTotal').attr("value") != "0" &&
		$('#HoroSecondTotal').attr("value") != "0") {
		if ($('#SexFirstTotal').attr("value") == 1) {
		    this.location.href = '/Compatibility/' +
					$('#HoroFirstTotal').attr("value") + '/' +
					$('#HoroSecondTotal').attr("value");
		}
		else if ($('#SexFirstTotal').attr("value") == 2) {
			this.location.href = '/Compatibility/' +
						$('#HoroSecondTotal').attr("value") + '/' +
						$('#HoroFirstTotal').attr("value");
						
		}
		Header.HideAllTitleItemBlocks();
	}
}

function CheckPartnerDayFirst() {
	if ($('#SexFirst').attr("value") == '1')
		$('#SexSecond').attr("value", 2);
	else if ($('#SexFirst').attr("value") == '2')
		$('#SexSecond').attr("value", 1);
	DisplayHoroDayCompatibility()
}
function CheckPartnerDaySecond() {
	if ($('#SexSecond').attr("value") == '1')
		$('#SexFirst').attr("value", 2);
	else if ($('#SexSecond').attr("value") == '2')
		$('#SexFirst').attr("value", 1);
	DisplayHoroDayCompatibility()
}

function CheckPartnerFirstTotal() {
	if ($('#SexFirstTotal').attr("value") == '1')
		$('#SexSecondTotal').attr("value", 2);
	else if ($('#SexFirstTotal').attr("value") == '2')
		$('#SexSecondTotal').attr("value", 1);
	DisplayHoroCompatibility()
}
function CheckPartnerSecondTotal() {
	if ($('#SexSecondTotal').attr("value") == '1')
		$('#SexFirstTotal').attr("value", 2);
	else if ($('#SexSecondTotal').attr("value") == '2')
		$('#SexFirstTotal').attr("value", 1);
	DisplayHoroCompatibility()
}    


function Hair(datetext) {
	$.getJSON('/Horoscope/HoroHair/' + datetext, function(data) {
	$('#horo_hair').text(data);
	});
	Header.HideAllTitleItemBlocks();
};
