/*$(function(){
	$('.jcarousel-skin-tango').jcarousel();
	$('.indexMenu>li').hover(function(){
		$(this).fadeTo(200,1);
		$('.indexMenu li').not($(this)).find('.imageContainer').fadeTo(500,0.4);
		$(this).find('.submenuContainer').show();
		var submenu = $(this).find('.submenuContainer .submenu .clearfix');
		submenu.width(0);
		submenu.find('ul:first>li').each(function(){
			submenu.width(submenu.width()+$(this).width());
		})
		$(this).find('.submenuContainer .submenu').children().hide().fadeIn();
	},function(){
		$('.indexMenu li').find('.imageContainer').fadeTo(200,1);
		$(this).find('.submenuContainer').hide();
	})

})*/
var weatherIcon = []


$(document).ready(function(){
	var inAnim;
	var outAnim;
	$('.jcarousel-skin-tango').jcarousel({wrap:"circular"});
	$('.indexMenu>li').hover(function(){
		clearTimeout(outAnim)
		var myDummy = $(this);
		inAnim = setTimeout(function(){mouseIn(myDummy)}, 100)
	},function(){
		clearTimeout(inAnim)
		var myDummy = $(this);
		outAnim = setTimeout(function(){mouseOut(myDummy)}, 100)

	})
	$('.menu>ul>li').hover(function(){
		clearTimeout(outAnim)
		var myDummy = $(this);
		inAnim = setTimeout(function(){mouseIn2(myDummy)}, 100)
	},function(){
		clearTimeout(inAnim)
		var myDummy = $(this);
		outAnim = setTimeout(function(){mouseOut2(myDummy)}, 100)

	})
	
	$('body').click(function(){
		$('.dropdown:not(.select)').removeClass('selected');
	})
	$('.dropdown').hover(function(){
		$(this).addClass('select')
	},function(){
		$(this).removeClass('select')
	})
	$('.dropdown').click(function(){
		$('.dropdown').removeClass('selected')
		$(this).addClass('selected')
	})
	$('.selectBox').each(function(){
		$(this).find('select').change(function(){
			$(this).siblings('span').text($(this).find('option[value="'+$(this).val()+'"]').text());		
		})
		$(this).find('select').change();
	})
	
	//colorbox start
	$(".gallery").each(function(i){
		$('.group'+(i+1)).colorbox({rel:'group'+(i+1)});
	})
	$(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	//color end
	
	$('.bottomShadow').hover(function() {
			$(this).find('div.index-banner-layer').stop(false,true).fadeIn(700);
		},
	function() {
			$(this).find('div.index-banner-layer').stop(false,true).fadeOut(700);
	});
		
	$( ".datepicker" ).datepicker({
		showOn: "button",
		buttonImage: "../img/dropdown/datepick.jpg",
		buttonImageOnly: true,
		onSelect: function(){
			$('body').unbind('click');
		},
		onClose: function(dateText, inst) {
			setTimeout(function() {
				$('body').click(function(){
					$('.dropdown:not(.select)').removeClass('selected');
				})
			},100);
		}
	});
	
	$('.language .content a').click(function(e){
		e.preventDefault();
		var path = window.location.href;
		
		$('.language .content a').each(function(){
			var language = $(this).attr('href').split('../')[1]
			path = path.split(language).join('%language%');
		})
		window.location.href = path.split('%language%').join($(this).attr('href').split('../')[1]);
	})
	
	$('.bannerCycle').cycle({timeout:5000});
	
	/*var script = ''
	$('.fb-like').attr('data-href',window.location.href)
	$('body').append(script);*/
})
function mouseIn(target){
	
	//alert($('.indexMenu li').not(target).length)
	target.find('.imageContainer').fadeTo(200,1);
	$('.indexMenu li').not(target).find('.submenuContainer').hide().end().find('.imageContainer').fadeTo(500,0.4);
	target.find('.submenuContainer').show();
	var submenu = target.find('.submenuContainer .submenu .clearfix');
	submenu.width(0);
	submenu.find('ul:first>li').each(function(){
		submenu.width(submenu.width()+$(this).width());
	})
	target.find('.submenuContainer .submenu').children().hide().fadeIn();
	$('#banner').fadeTo(500,0.5)
}

function mouseIn2(target){	
	//alert($('.indexMenu li').not(target).length)
	$('.menu>ul>li').not(target).find('.submenuContainer').hide().end().find('.imageContainer').fadeTo(500,0.4);
	target.find('.submenuContainer').show();
	var submenu = target.find('.submenuContainer .submenu .clearfix');
	submenu.width(0);
	submenu.find('ul:first>li').each(function(){
		submenu.width(submenu.width()+$(this).width());
	})
	target.find('.submenuContainer .submenu').children().hide().fadeIn();
}

function mouseOut(target){
	$('.indexMenu li').find('.submenuContainer').hide().end().find('.imageContainer').fadeTo(200,1);
	$('#banner').fadeTo(500,1)
}

function mouseOut2(target){
	$('.menu>ul>li').find('.submenuContainer').hide().end().find('.imageContainer').fadeTo(200,1);
}

var time = null;
function jsonTime(json){
	//timeCode = json;
	//console.log(json['data']['time_zone'][0]['localtime'])
	time = json['data']['time_zone'][0]['localtime'].split(' ')[1].split(':');
	//console.log(time)
	///*var time = timeCode['hour']%12
	var hours = time[0]
	var minute = time[1]
	time = ((hours==12)?12:(hours%12))+':'+minute+' '+((hours<12)?'AM':'PM');
	//console.log(time+' '+((hours<12)?'AM':'PM'))
	//alert($('.weatherInformation .time').length)
	$('.weatherInformation .time').filter(function(){return !$(this).parent().hasClass('hide')}).append(time)
}

function getWeather(){
	if($('.weatherInformation').length>0){
	for(i in locationCode){
		//var data = location[i];
		$('.weatherInformation .cycle').append($('.weatherInformation .hide').clone().removeClass('hide').addClass(i.toLowerCase()));
		$.simpleWeather({
			zipcode: locationCode[i]['code'],
			unit: 'c',
			success: function(weather) {		
				var wc = $('.weatherInformation .'+weather['city'].toLowerCase())
				wc.find('.temp').html(weather['temp']+'&deg;C');
				wc.find('.location').html(locationCode[weather['city']]['label'])
				var icon = null
				if(weatherIcon[weather['code']] != null){
					weatherimg = weatherIcon[weather['code']];
				}else{
					weatherimg = weather['thumbnail'];
				}
				if(weatherimg.indexOf("3200ds")>0) {
					weatherimg = weatherimg.replace('00','');
				}
				icon = $('<img src="'+weatherimg+'"/>');
				wc.find('.icon').html(icon);
				$('.weatherInformation .cycle .'+weather['city'].toLowerCase()).removeClass('loading').children().fadeIn();
				//console.log(weather);
				//$('#content .header .temp').html(weather['temp']);
			},
			error: function(error) {
				//$("#weather").html("<p>"+error+"</p>");
			}
		});
	}
	$('.weatherInformation .cycle').cycle({timeout:5000,cleartypeNoBg: true})
	$('.weatherInformation .cycle .record').addClass('loading').children().hide();
	if(time != null){
		$('.weatherInformation .time').filter(function(){return !$(this).parent().hasClass('hide')}).append(time)
	}
	}
}




