// Visual Studio intelisense references :
///<reference path="../../../../../../misc/jquery-vsdoc.js" />
///<reference path="../../../../../../misc/drupal.js" />

/*
$(function() {
    setTimeout(function() {
        $('#slideshow div:first').fadeIn(2000);
        $('#slideshow').cycle();
    }, 1000);
});

$(function() {
	$('.pics img').css({
        opacity: 0
    });
    setTimeout(function() {
        $('#slideshow').cycle({
            random: 1,
            delay:  -2000
        });
	    $('.pics img').css({
	        opacity: 0
	    });
    }, 1000);
});

*/


$(document).ready(function() {

	if ($('#tabs-video-top-last').length > 0) {
		$('#tabs-video-top-last').tabs();
	}

	//if( $('#tabs-videoarchive-top-relevant-discussion').length > 0) {
	//	$('#tabs-videoarchive-top-relevant-discussion').tabs();
	//}

	if ($('#sliderContent').length > 0) {

		function pagerFactory(idx, slide) {
			var s = idx % 2 ? ' style="display:none"' : '';
			s = '';
			return '<a class="pngfix" href="#slide-' + (idx + 1) + '" ' + s + '>' + (idx + 1) + '</a>';
		};

		function onAfter(curr, next, opts) {
			var index = opts.currSlide;
			$('#prev')[index == 0 ? 'hide' : 'show']();
			$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
		};

		$('#sliderContent').cycle({
			fx: 'fade',
			speed: 1000,
			timeout: 5000,
			pauseOnPagerHover: 1,
			pager: '#controls',
			pause: 1,
			next: '#next',
			prev: '#prev',
			delay: -500,
			cleartype: 1,
			pagerAnchorBuilder: pagerFactory,
			after: onAfter,
			slideExpr: 'div.slide'
		});

		$('#pause').click(function() { $('#sliderContent').cycle('pause'); return false; });
		$('#play').click(function() { $('#sliderContent').cycle('resume'); return false; });
		$('#sliderContainer').hover(
	        function() { $('#sliderControls').fadeIn(); $('#controls').fadeIn(); },
	        function() { $('#sliderControls').fadeOut(); $('#controls').fadeOut(); }
	    );
	}

	if ($('.prima-kino-container ul').length) $('.prima-kino-container ul').kwicks({ max: 280, duration: 300, easing: 'easeOutQuad', complete: 'callback' });

	if ($("#topSliderTab").length) {
		var activeClass = 'active';
		var marginTopDefault = 0;
		$("#topSliderTab").click(function() {
			var topSliderContainer = $("#topSliderContainer");
			if (!topSliderContainer.hasClass(activeClass)) {
				marginTopDefault = topSliderContainer.css('margin-top');
				topSliderContainer.animate({ marginTop: 0 }, 500);
				topSliderContainer.addClass(activeClass);
			} else {
				topSliderContainer.removeClass(activeClass);
				topSliderContainer.animate({ marginTop: marginTopDefault }, 500);
			}
		});
	}


	/* BUTTONS */
	if ($('.fg-button').length) {
		$('.fg-button').hover(
                    function() { $(this).removeClass('ui-state-default').addClass('ui-state-focus'); },
                    function() { $(this).removeClass('ui-state-focus').addClass('ui-state-default'); }
        );
	}

	/* MENUS */
	if ($('.page-videoarchive .videoarchive-choose-program .select-box-button').length) {
		$('.videoarchive-choose-program .select-box-button').each(function() {
			$(this).menu({
				content: $(this).parent().find(".select-box-items-container .item-list").html(),
				//content: $(this).parent().find(".select-box-items-container").html(),
				maxHeight: 250,
				width: 260,
				positionOpts: {
					posX: 'left',
					posY: 'bottom',
					offsetX: -7,
					offsetY: -1,
					directionH: 'right',
					directionV: 'down',
					detectH: false, // do horizontal collision detection
					detectV: false, // do vertical collision detection
					linkToFront: false
				},
				showSpeed: 300

			});

		});
	} else if ($('.select-box-button').length) {
		$('.select-box-button').each(function() {
			$(this).menu({
				content: $(this).parent().find(".select-box-items-container .item-list").html(),
				//content: $(this).parent().find(".select-box-items-container").html(),
				maxHeight: 250,
				width: 260,
				positionOpts: {
					posX: 'left',
					posY: 'bottom',
					offsetX: -3,
					offsetY: -5,
					directionH: 'right',
					directionV: 'down',
					detectH: false, // do horizontal collision detection
					detectV: false, // do vertical collision detection
					linkToFront: false
				},
				showSpeed: 300
			});

		});
	}

	//default styles
	if ($.fn.qtip && $.fn.qtip.styles) {
		$.fn.qtip.styles.iprima = { // Last part is the name of the style
			border: {
				width: 2,
				radius: 5,
				color: '#000000'
			},
			width: 289,
			padding: 0,
			background: '#000000',
			textAlign: 'left',
			tip: {
				corner: 'bottomLeft',
				size: {
					x: 5,
					y: 5
				}
			}
		}
	}

	if ($('#leftContainer .tvprogram-options-link').length) {
		$('#leftContainer .tvprogram-options-link').each(function() {
			var id = $(this).attr('rel');
			var content = $('#tvprogram-details-container-' + id).html();
			$(this).qtip({
				content: {
					text: content
				},
				position: {
					corner: {
						tooltip: 'bottomLeft',
						target: 'topLeft'
					},
					adjust: { x: 30, y: -3, screen: true, mouse: false }
				},
				show: {
					when: 'click',
					solo: true // hide all other tooltips
				},
				hide: {
					when: 'click'
				},
				style: 'iprima'
			});
		});

		$('#leftContainer .tvprogram-options-link').click(function(event) {
			if (event.stopPropagation) { event.stopPropagation(); } //For 'Good' browsers
			else { event.cancelBubble = true; } //For IE

			return false;
		});
	}

	/* Login/Registration from content - show panel */
	var activeLoginRegistration = false;
	$(".btn-prihlaseni-registrace").click(function(event) {
		if (activeLoginRegistration == false) {
			$("div#panel").slideDown("slow");
			$("#toggle a").toggle();
			activeLoginRegistration = true;
		} else {

		}

		$.scrollTo('div#panel', 800);

		return false;
	});

	/* Expand Panel */
	$(".open").click(function() {
		$("div#panel").slideDown("slow");
		return false;
	});
	$(".top-title").click(function() {
		$("div#panel").slideDown("slow");
		$("#toggle a").toggle();
		return false;
	});


	/* Collapse Panel */
	$(".close").click(function() {
		$("div#panel").slideUp("slow");
	});

	/* Switch buttons from "Log In | Register" to "Close Panel" on click */
	$("#toggle a").click(function() {
		$("#toggle a").toggle();
	});


	/* Pasted from jsuchy.js */
	// Add to any link, Print
	$('.node-links .addtoany .a2a_dd').html('<span class="share"><span class="icon icon-share-17x24"></span>sdílet</span>');
	$('#a2apage_EMAIL').css('display', 'none');
	$('#a2apage_amazon_wish_list').css('display', 'none');
	$('.prima_print a').click(function() {
		window.print();
		return false;
	});


	// Form errors
	var shown = 0;
	$('.login-box #user-login .error').each(function() {
		if (shown == 0) { shown = 1; $("div#panel").slideDown("slow"); $("#toggle a").toggle(); }
	});
	$('.register-box #user-register .error').each(function() {
		if (shown == 0) { shown = 1; $("div#panel").slideDown("slow"); $("#toggle a").toggle(); }
	});

	// Add pngfix to carousel in node view for gallery.
	//    $('.jcarousel-prev').addClass('pngfix');
	//  $('.jcarousel-next').addClass('pngfix');


	$(".select-box div").css("display", "none");
	$(".select-box span").click(function() {
		$(this).next().slideToggle("fast");
	});
	/* end temporary */

	/* Tonight */
	$(".view-b02-tonight .views-row-2 .views-field-title").css("display", "none");
	$(".view-b02-tonight .views-row-3 .views-field-title").css("display", "none");
	$(".view-b02-tonight .views-row-4 .views-field-title").css("display", "none");
	/* Make first active */
	$(".view-b02-tonight .views-row-1 .views-field-field-time-start-value").addClass('tonight-active');

	$(".view-b02-tonight .views-row .views-field-field-time-start-value").mouseover(function() {
		$(".view-b02-tonight .views-row .views-field-title").each(function() {
			$(this).css('display', 'none');
		});
		$(".view-b02-tonight .views-row .views-field-field-time-start-value").each(function() {
			$(this).removeClass('tonight-active');
		});
		$(this).addClass('tonight-active');
		$(this).next('.views-field-title').css('display', 'block');
	});

	/* Tonight end */

	/* Porady TV prima - zmena odpalu od spodni hrany pri dvouradkovem textu */
	if ($('#primaPoradyContainer .views-field-title a').height() > 16) {
		$('#primaPoradyContainer .views-field-title').css('bottom', '9px');
	}

});

  function primacarousel_initCallback(carousel) {
    jQuery('.jcarousel-control a').bind('click', function() {
          carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
          return false;
          });
      jQuery('.jcarousel-scroll select').bind('change', function() {
          carousel.options.scroll = jQuery.jcarousel.intval(this.options[this.selectedIndex].value);
          return false;
          });
    /* start final! */
    jQuery('#primacarousel-next').bind('click', function() {
      carousel.next();
      return false;
      });

    jQuery('#primacarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
        });
    };
