$(document).ready(function(){
	setTimeZoneCookie();

	$(".imagelist .arrow").click(function(){
		$(this).parent().parent().parent().find(".arrow img").toggle();
		$(this).parent().parent().parent().find(".bannername").toggle();
		$(this).parent().parent().parent().find(".editban").toggle();
		$(this).parent().parent().parent().next().toggle();
	})

	$(".imagelist .save_banner").click(function(){
		$(this).parent().parent().parent().parent().parent().slideToggle();
	})

	$(".menu_switch").click(function(){
		$(".menu_switch").toggle();
		$(".global").toggleClass("menu_opened").toggleClass("menu_closed");
	})

	$("a[href$=.jpg],a[href$=.png],a[href$=.gif],a[href$=.JPG],a[href$=.PNG],a[href$=.GIF]").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600,
		'speedOut'		:	200,
		'overlayShow'	:	true,
        'padding'		: 0,
        'autoScale'		: false
	});


/*============================================================================*/
	if (window.self != window.top){
		var url = window.self.location.toString();
		url = url.split('?')[0];
		window.top.location = url;
	}

	$.support.borderRadius = false;
	$.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius'], function() {
		if(document.body.style[this] !== undefined) $.support.borderRadius = true;
		return (!$.support.borderRadius);
	});

	$('#tl-select').click(function(e){
		var obj = $('#tl-list');
		if (obj.hasClass('active')) {
			obj.removeClass('active')
			$('body').unbind('click');
		}
		else {
			obj.addClass('active');
			$('#tu-auth, #t-user').removeClass('active');
			$('body').click(function(e){
				var target = e.target;
				var close = true;
				while (target) {
					if (target.getAttribute && target.getAttribute('id') == 'tl-list') {
						close = false;
						break;
					}
					target = target.parentNode;
				}
				if (close) {
					$('#tl-list').removeClass('active');
				}
			});
		}
		e.preventDefault();
		e.stopPropagation();
	});

	$('#tu-login').click(function(e){
		var obj = $('#tu-auth');
		var linkObj = $('#t-user');
		if (obj.hasClass('active')) {
			obj.removeClass('active')
			linkObj.removeClass('active');
			$('body').unbind('click');
		}
		else {
			$('#tl-list').removeClass('active');
			obj.addClass('active');
			linkObj.addClass('active');
			$('body').click(function(e){
				var target = e.target;
				var close = true;
				while (target) {
					if (target.getAttribute && target.getAttribute('id') == 'tu-auth') {
						close = false;
						break;
					}
					target = target.parentNode;
				}
				if (close) {
					$('#tu-auth, #t-user').removeClass('active');
				}
			});
		}
		e.preventDefault();
		e.stopPropagation();
	});

	if (!('placeholder' in document.createElement('input'))) {
		$('input[placeholder]').each(function(){
			var obj = $(this);
			if (obj.val() == '') {
				obj.val(obj.attr('placeholder'));
			}
			obj.focus(function(){
				var obj = $(this);
				if (obj.val() == obj.attr('placeholder')) {
					obj.val('');
				}
			});
			obj.blur(function(){
				var obj = $(this);
				if (obj.val() == '') {
					obj.val(obj.attr('placeholder'));
				}
			});
		});
	}

	$('#menu li').hover(function(){
		$(this).addClass('active');
	}, function(){
		$(this).removeClass('active');
	});

	$('select').styledSelect();
	$('input:radio').dqRadiobox();
	$('input:checkbox').dqCheckbox();

	$('.rqc-switch').click(function(e){
		var obj = $(this);

		$('.rqc-switch.active').removeClass('active');
		obj.addClass('active');

		$('.rq-list-wrapper.active').removeClass('active');
		$('#' + obj.attr('rel')).addClass('active');

		e.preventDefault();
	});

	$('#ss-caption a').click(function(e){
		var obj = $(this);

		$('#ss-caption a.active').removeClass('active');
		obj.addClass('active');

		$('.ss-content').removeClass('active');
		$('#' + obj.attr('rel')).addClass('active');

		e.preventDefault();
	});

//	if (!$.support.borderRadius) {
		$('button').each(function(){
			var obj = $(this);

			var styled = $('<span></span>');
			styled.addClass(obj.attr('class'));
			var styledHelper = $('<span></span>');
			styledHelper.text(obj.text());
			styled.append(styledHelper);
			styled.click(function(){
				obj.click();
			});
			obj.hide();
			obj.before(styled);
		});
//		}

	$('.likeSelect .selected, .likeSelect .first').click(function(e){
		//$('.likeSelect').toggleClass('opened');
		$(this).parents('.likeSelect').toggleClass('opened');
		e.preventDefault();
	});

});

function setTimeZoneCookie()
{
	if($.cookie('time_zone') == null){
		$.cookie('time_zone', ((new Date()).getTimezoneOffset()/60 *-1)-1, {path: '/', domain: document.domain});
	}
}

function hideShadowbox(){
	Shadowbox.close();
}

function openCalendar(){
	if ($('#calendar:visible').size() == 0){
		$('#calendar').show();
		$('body').bind('click', closeCalendar);
	} else {
		closeCalendar();
	}
}

function closeCalendar(){
	$('#calendar').hide();
	$('body').unbind('click', closeCalendar);
}

function unBuble(event) {
	event = event || window.event;
	event.cancelBubble = true;
	if (event.stopPropagation) {
		event.stopPropagation();
	}
}

function catcher(event, button){
	var keyCode = event.which ? event.which : event.keyCode;
	if (keyCode == 13){
		if (typeof(button) === 'function'){
			button();
		}

		if (button[0] !== undefined){
			makeClick(button[0]);
		}
	}
	return false;
}

function makeClick(obj){
	if (typeof(obj.fireEvent) == 'function' || typeof(obj.fireEvent) == 'object'){
		obj.fireEvent('onclick');
	} else {
		var anEvent = document.createEvent("MouseEvents");
		anEvent.initMouseEvent("click", false, false, null, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		obj.dispatchEvent(anEvent);
	}
}

function registerSaveFunction(callback_func, target_obj){
	if (typeof(callback_func) != 'function') return;
	target_obj = target_obj || document;

	var add_event = ($.browser.msie) ? "keydown" : "keypress";
	$(target_obj).bind(add_event, function(event){hotSave(event, callback_func);});
}

function hotSave(evt, callback_func)
{
	evt = evt || window.event;
	var key = evt.keyCode || evt.which;

	key = String.fromCharCode(key).toLowerCase() == "s";

	if (evt.ctrlKey && key) {
		if(evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		callback_func();
		return false;
	}
}

function key_enter(event) {
    if(event.keyCode==13) return true;
    return false;
}

// Kayako LiveHelp
var chatwindow = false;

function startChat()
{
 if (chatwindow && !chatwindow.closed) return false;

 var myWidth = 0, myHeight = 0;
 if( typeof( window.innerWidth ) == 'number' ) {
 //Non-IE
 myWidth = window.innerWidth;
 myHeight = window.innerHeight;
 } else if( document.documentElement &&
 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
 //IE 6+ in 'standards compliant mode'
 myWidth = document.documentElement.clientWidth;
 myHeight = document.documentElement.clientHeight;
 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
 //IE 4 compatible
 myWidth = document.body.clientWidth;
 myHeight = document.body.clientHeight;
 }
 winH = myHeight;
 winW = myWidth;

 docWidth = (winW-500)/2;
 docHeight = (winH-480)/2;

 chatwindow = window.open(dqConfig.lk_domen +"/livesupport/","customerchat", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=500,height=480,left="+docWidth+",top="+docHeight);
 }
/*=============================================================================*/

