﻿/* document ready */

$(document).ready(function() {
	
	/* mod-news functions */
	$(".mod-news .mod-news-header ul li a").live("click",function() {
		$(this).parents(".mod-news").find(".mod-news-header ul li a:first").css({backgroundColor:"white"});
		$(this).parents(".mod-news").find(".mod-news-header ul li a").removeClass("active-mod-news");
		$(this).addClass("active-mod-news");
		$(this).parents(".mod-news").find(".mod-news-section").hide();
		$(this).parents(".mod-news").find("div#mod-news-section"+$(this).attr("rel")).show();
		$(this).parents(".mod-news ul").prepend($(this).parent().remove());
	});
	
	if($.browser.msie && $.browser.version <= 6)
	{
		var weatherBg = $(".mod-weather img").attr("src");
		$(".mod-weather img").css({
			background : "none",
			filter : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", src="'+weatherBg+'", sizingMethod="crop")'
		});
		$(".mod-weather img").attr("src", "Templates/Images/Dedeman/blank.gif");
	}
	
	/* mod-newsticker functions */
	$(".mod-newsticker .newsticker-area div").jCarouselLite({
		auto : 1000,
		speed : 1000,
		visible : 1,
		vertical : true
	});
	
	/* dynamic input value */
	$("input.value-control").attr("value",function() {
		return $(this).attr("title");
	}).focus(function() {
		if ($(this).attr("title") == $(this).val()) {
			$(this).val("");
		}
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("title"));
		}
	});
	
	/* sub left menu functions */
	$(".mod-sub-menu ul li").not(".mod-sub-menu ul li.last-sub-menu-item").append("<div class=\"seperator1\">&nbsp;</div>");
	
	/* font size matic functions */
	var fontSize = 11;
	$(".sizematic span a").eq(0).click(function() {
		if (fontSize < 17) {
			++fontSize;
		}
		$("."+$(this).parent().attr("id")).css("font-size",fontSize);
	});
	$(".sizematic span a").eq(1).click(function() {
		if (fontSize > 10) {
			--fontSize;
		}
		$("."+$(this).parent().attr("id")).css("font-size",fontSize);
	});
	
	/* image gallery functions */
	
	$(".mod-image-gallery a").click(function(e) {
		e.preventDefault();
		$(this).parents(".mod-image-gallery").find(".big-image img").attr("src",$(this).attr("href"));
	});
	
	
	
	/* mod-events functions */
	$(".mod-events .mod-events-control ul li a").live("click",function() {
		$(this).parents(".mod-events").find(".mod-events-control ul li a").removeClass("active-events-item");
		$(this).addClass("active-events-item");
		$(this).parents(".mod-events").find(".mod-events-item").hide();
		$(this).parents(".mod-events").find("div#mod-events-item"+$(this).attr("rel")).show();
	});
	
	/*Rates And Availability UC / Country [adem]*/
	$("#ddlCountry").change(function(){
		var CountryID=$("#ddlCountry option:selected").val();
		if(CountryID!=0)
		{
			$("#ddlCity").html("");
			$("#ddlHotel").html("");
			if ($('.ddlLocaleList').find(':selected').val() == '55')
			{
				$("#ddlHotel").append($("<option></option>").val(0).html("Otel Seçiniz"));
			}
			else
			{
				$("#ddlHotel").append($("<option></option>").val(0).html("Select Hotel"));
			}
			$.getJSON('RatesAndAvailabilityRequest.ashx?CountryID='+CountryID+'&LocaleId='+$('.ddlLocaleList').find(':selected').val(), function(cities) {
				$.each(cities,function(){
					$("#ddlCity").append($("<option></option>").val(this['ID']).html(this['City']));
				});
			});
		}else{
			$("#ddlCity").html("");
			if ($('.ddlLocaleList').find(':selected').val() == '55')
			{
				$("#ddlCity").append($("<option></option>").val("0").html("Lokasyon Seçiniz"));
			}
			else
			{
				$("#ddlCity").append($("<option></option>").val("0").html("Select Location"));
			}
			$("#ddlHotel").html("");
			if ($('.ddlLocaleList').find(':selected').val() == '55')
			{
				$("#ddlHotel").append($("<option></option>").val("0").html("Otel Seçiniz"));
			}
			else
			{
				$("#ddlHotel").append($("<option></option>").val("0").html("Select Hotel"));
			}
		}
	});
	
	
	
		
			$.getJSON('RatesAndAvailabilityRequest.ashx?LocaleId='+$('.ddlLocaleList').find(':selected').val(), function(hotels){
				$.each(hotels,function(){
					$("#ddlHotel").append($("<option></option>").val(this['ID']).html(this['Hotel']));
				});
			});
		

	/*Rates And Availability UC / City [adem]*/
	$("#ddlCity").change(function() {
		var CityID=$("#ddlCity option:selected").val();
		if (CityID!=0)
		{
			$("#ddlHotel").html("");
			$.getJSON('RatesAndAvailabilityRequest.ashx?CityID='+CityID+'&LocaleId='+$('.ddlLocaleList').find(':selected').val(), function(hotels){
				$.each(hotels,function(){
					$("#ddlHotel").append($("<option></option>").val(this['ID']).html(this['Hotel']));
				});
			});
		}else{
			$("#ddlHotel").html("");
			if ($('.ddlLocaleList').find(':selected').val() == '55')
			{
				$("#ddlHotel").append($("<option></option>").val("0").html("Otel Seçiniz"));
			}
			else
			{
				$("#ddlHotel").append($("<option></option>").val("0").html("Select Hotel"));
			}
		}
	});
	
	/*Rates And Availability UC / Book [adem]*/
	$("#lbBookNow").click(function(){
		var HotelID = $("#ddlHotel option:selected").val();
		if (HotelID!=0)
		{
			$.getJSON('RatesAndAvailabilityRequest.ashx?HotelID='+HotelID+'&CheckIn='+$("input[id*=dtCheckIn_Picker_selecteddates]").val()+'&CheckOut='+$("input[id*=dtCheckOut_Picker_selecteddates]").val()+'&LocaleId='+$('.ddlLocaleList').find(':selected').val(), function(link){
				$.each(link,function(){
					if (this['IsValid']>0){
						createCookie('popupUrl', this['Url'], '');
						window.location.replace(this['Redirect']);
					}
					else
					{
						if ($('.ddlLocaleList').find(':selected').val() == '55')
						{	
								alert('Lütfen geçerli bir tarih aralığı seçiniz.');
						}
						else
						{
							   alert('Please select a valid date range.');
						}
						
					}
				});
			});
		}
		else
		{
			if ($('.ddlLocaleList').find(':selected').val() == '55')
			{
				alert('Otel Seçiniz');
			}
			else
			{
				alert('Select Hotel');
			}
		}
	});
	
	$("div.mod-tabbed-trigger ul li a").click(function(e) {
	e.preventDefault();
	$("div.mod-tabbed").hide();
	$($(this).attr("href")+".mod-tabbed").show();
	});
	
	
	// silinecek kodlar
	
	$("#mod-news-section0 .mod-spot-content-item:last, #mod-news-section1 .mod-spot-content-item:last").addClass("last-mod-spot-content-item");
	/*$(".mod-image-gallery li").each(function(i) {
		if ((i+1) % 4 == 0) {
			$(this).addClass("last-image-gallery-item");	
		}
	});*/
	
});

function Popup2(url,target,properties)
{
var pop;	
	if (target == '_self')
	{	
		pop = window.open(url, '_self');
	}
	else if (target == '_blank_')
	{
		pop = window.open(url, '_blank');
	}
	else
	{
		var strwidth = 'width';
		var strheight = 'height';
		var strStatus = 'status';
		var startIndex ;
		var endIndex ;
		var width ;
		var height ;
		startIndex = properties.indexOf(strheight);
		strheight = strheight + '=';
		startIndex = startIndex + strheight.length;
		endIndex = properties.indexOf(strwidth);
		height = properties.substring(startIndex,endIndex-1);	
		
		startIndex = properties.indexOf(strwidth);
		strwidth = strwidth + '=';
		startIndex = startIndex + strwidth.length;
		endIndex = properties.indexOf(strStatus);				
		width = properties.substring(startIndex,endIndex-1);
		
		var leftDim = (screen.width - width) / 2;
		var topDim = (screen.height - height) / 2;
		var hwString = 'left=' + leftDim + ',top=' + topDim + ',' + properties;				
		pop = window.open(url, '_blank', hwString);							
	}
	if (pop == null){
		alert('Pencere acilamadi. Lutfen pencere engelleyicinizi kapatiniz.');
	}
	return false;	
}

function imageGallery() {
				var ig = {
					count : 0,
					active : 0,
					items : [],
					init : function(galleryID) {
						this.count = this.items.length;
						if (this.count > 1)
						{
							$("div#"+galleryID+".imageGallery div.imageGalleryContainer").after('<ul class="imageGalleryNav clearfix" style="font-size:11px;"><li><a class="prev button button-type1" href="javascript:;"><span>Geri</span></a></li><li><a class="next button button-type1" href="javascript:;"><span>İleri</span></a></li></ul>');
						}
						$("div.imageGallery ul.imageGalleryNav li a").bind("click", function(e) {
							if ($(this).hasClass("next") > -1)
							{
								ig.active++;
								if (ig.active == ig.count)
								{
									ig.active = 0;
								}
							}
							else
							{
								ig.active--;
								if (ig.active < 0)
								{
									ig.active = ig.count - 1;
								}
							}
							$(this).parents("div.imageGallery").find("div.imageGalleryContainer img").attr("src", ig.items[ig.active]);
						});
					}
				}
				return ig;
			}
//cookie to popup
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 var 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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
