﻿
$(document).ready(function() {

    $.easy.tooltip();
    //$.easy.external();
    $.easy.showhide();
    $.easy.jump();
    $.easy.forms();

    $("#featured-films  .moviePlayer").click(function() {
        $("#featured-films").cycle('stop');
    });

    $(".charCount").charCount({
        allowed: 500,
        warning: 20,
        counterText: 'Kalan karakter: '
    });

    $(".charCountLarge").charCount({
        allowed: 1000,
        warning: 20,
        counterText: 'Kalan karakter: '
    });

    // featured films slideshow
    $("#featured-films").cycle({
        //fx: 'scrollDown',
        speed: 1000,
        timeout: 7500,
        pause: 1,
        cleartype: 1
    });

    // SUCCESS AJAX CALL, replace "success: false," by:     success : function() { callSuccessFunction() },
    $("form").validationEngine();

    //$.validationEngine.loadValidation("#date")
    //alert($("#formID").validationEngine({returnIsValid:true}))
    //$.validationEngine.buildPrompt("#date","This is an example","error")	 		 // Exterior prompt build example								 // input prompt close example
    //$.validationEngine.closePrompt(".formError",true) 							// CLOSE ALL OPEN PROMPTS

    // transition effect
    style = 'easeOutQuart';

    // if the mouse hover the image

    $('#movieList .vevent').hover(
		function() {
		    //hide heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ bottom: -30 }, { duration: 500, easing: style });
		},
		function() {
		    //display heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ bottom: 1 }, { duration: 500, easing: style });
		}
	);

    $('#movieSubList .vevent').hover(
		function() {
		    //hide heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ bottom: -30 }, { duration: 500, easing: style });
		},
		function() {
		    //display heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ bottom: 1 }, { duration: 500, easing: style });
		}
	);

    $('#seasonList .vevent').hover(
		function() {
		    //hide heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ width: 590 }, { duration: 500, easing: style });
		},
		function() {
		    //display heading and caption
		    $(this).children('div.caption').stop(false, true).animate({ width: 585 }, { duration: 500, easing: style });
		}
	);

    // Absolute positions for each event on event calendar
    $('#event_calendar .vevent').each(function() {
        var hcard = $(this);
        var ratio = 1.5;

        var dtstart = hcard.find('.dtstart').attr('title')
                                            .replace(':', '.');

        var hour = dtstart.substring(0, dtstart.lastIndexOf('.'));
        hour = parseInt((hour - 11) * 60);
        var minute = parseInt(dtstart.substring(dtstart.lastIndexOf('.')).replace('.', ''));
        dtstart = parseInt((hour + minute) * 1.5);

        var dtend = hcard.find('.dtend').attr('title') * 1.5;
        var duration = (hcard.find('.duration').attr('title') * 1.5) - 5;
        var location = hcard.find('.location').attr('title');
        location = parseInt((location - 1) * 119);

        if (dtstart == 0) {
            dtstart = 3;
        }

        if (dtstart < 3 && dtstart != 11) {
            dtstart = parseInt(dtstart + 2160);
        }

        $(this).attr('style', 'top:' + dtstart + 'px; left: ' + location + 'px; height: ' + duration + 'px;');
    });

    $('#event_calendar .hours a').click(function() {
        $(this).toggleClass('selected')
        return false;
    });

});

function setView(side, view) {
    $(side).removeClass('horizontal');
    $(side + ' .vevent div.caption').removeAttr('style');
    
    if (view == 'box') {
        $(side + ' .vevent').unbind('mouseenter mouseleave');
        $(side + ' .vevent').hover(
		        function() {
		            //hide heading and caption
		            $(this).children('div.caption').stop(false, true).animate({ bottom: -30 }, { duration: 500, easing: style });
		        },
		        function() {
		            //display heading and caption
		            $(this).children('div.caption').stop(false, true).animate({ bottom: 1 }, { duration: 500, easing: style });
		        }
	        );
    } else {
    $(side).addClass('horizontal');
        $(side + ' .vevent').unbind('mouseenter mouseleave');
        $(side + ' .vevent').hover(
		        function() {
		            //hide heading and caption
		            $(this).children('div.caption').stop(false, true).animate({ width: 590 }, { duration: 500, easing: style });
		        },
		        function() {
		            //display heading and caption
		            $(this).children('div.caption').stop(false, true).animate({ width: 585 }, { duration: 500, easing: style });
		        }
	        );
    }
}
