﻿var scrollCenter = true;
var messageBoxAutoHide = true;
var pageLoaded = false;
var autoResize = true;
var themePath = '';


$.getScript("../jquery.tipTip.js");
$.getScript("../incHeader.js");
$.getScript("../jquery.easing.js");
$.getScript("../jquery.scrollTo-min.js");
$.getScript("../jquery.timers.js");
$.getScript("../jquery.galleryview.js");

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function scrollToCenter()
{
    if (screen.width==1280)
    {
        if (parent==self)
        {
            $('div.sideBar').width(145);
        }
    }
    else
    {
            if (parent!==self)
            {
                
            }
            else
            {
                $.scrollTo( { top:'', left:'50%' }, 800, { axis:'x', easing:'easeOutBounce' } );
            }
    }
}

function errorPlacement($element)
{
    if ($element.length>0)
    {
        var $error = $('div.MessageBox');

        $error.slideUp('fast',function(){
            $error.children('span').append($('<div>x</div>')
                                            .addClass('Close')
                                            .click(function(){
                                            $(this).parent().parent().hide('fast');
                                            })
                                            );
            $error.removeClass('MessageBox');
            $error.addClass('Message');
            $element.before($error);
            
            $offset = $element.position();

            if ( $(document).width() < ($offset.left + $error.outerWidth()) )
            {
                $error.addClass('Right');
                $error.css('left', $offset.left  - $error.outerWidth() );
            }
            else
            {
                $error.css('left', $offset.left + $element.outerWidth());
            }
            
            if (($offset.top - (($error.outerHeight()-$element.outerHeight())/2))<0)
            {
                $error.css('top', 0);
            }
            else
            {
                $error.css('top', $offset.top - (($error.outerHeight()-$element.outerHeight())/2));
            }
                        
            $error.fadeIn();
            $.scrollTo($error,'fast');
            if (messageBoxAutoHide)
            {
                setInterval(function(){$error.fadeOut('slow');},10000);
            }
            $element.focus(function(){$error.fadeOut('slow');});
            $element.click(function(){$error.fadeOut('slow');});
        });
    }
}

function checkUniqueKey(uniqueKey, current, count)
{
var currentCount = 0;
    currentCount = $("input:[uniqueKey='" + uniqueKey + "'][checked=true]").length
    $("input:[uniqueKey='" + uniqueKey + "']").each(function(index)
                                                  {
                                                      if (this!==current && currentCount>count)
                                                      {
                                                           this.checked=false;
                                                      }
                                                  });
}

function createTipTip()
{
    if ($(".tipTip").length > 0) {
            $.getScript("jquery.tipTip.js", function () {
                $(".tipTip").tipTip( { defaultPosition:"left", content:"content", animationName:"fade", maxWidth:"300px" } );
            });
            
    }
}

function createGalleryView()
{
    if ($("#movieGalleryView").length > 0) {
        $('#movieGalleryView').galleryView({
            transition_interval:6000,
            nav_theme: 'light',
            theme_path: themePath + 'GalleryView/',
		    panel_width: 500,
		    panel_height: 249,
		    frame_width: 69,
		    frame_height: 87,
		    pause_on_hover: true,
		    start_frame: 1
	    });
	}
}

function iFrameBack() {
    if (parent !== self) {
        history.go(-1);
    } else {
        window.close();
    }
}

if(parent !== self) { 
    var iFrameDemand = function () {
        if (window.parent.pageLoaded) {
            if (autoResize)
            {
                window.parent.iFrameDemand(document.documentElement.scrollWidth, document.body.offsetHeight);
            }
        } else {
            setTimeout(iFrameDemand, 500);
        }
    }
}

function SchedulePanelNewStyle() {
    var $prevScheduleList = null;
//    $('.scheduleList').hide();
    $('.filmTitle').click(function () {

//        if ($prevScheduleList !== null && $prevScheduleList.get(0) !== $(this).get(0)) {
//            $prevScheduleList.next('.scheduleList').slideToggle(300);
//            $prevScheduleList.toggleClass('expanded');
//            $prevScheduleList = $(this);
//        } else if ($prevScheduleList !== null && $prevScheduleList.get(0) === $(this).get(0)) {
//            $prevScheduleList = null;
//        } else {
//            $prevScheduleList = $(this);
//        }
        $(this).next('.scheduleList').slideToggle(300, function () {
            iFrameDemand();
        });
        $(this).toggleClass('expanded');

    });
    $('.filmTitle').hover(function () {
        $(this).toggleClass('highLight');
    }); /* $('.panelPremiereStyle').each(function() { $(this).children('.filmDetail:last').children('.filmDivider').hide(); }); */
    $('.scheduleList').each(function () {
        $(this).children('.schedule:even').addClass('highLight');
    });
    $('.showTime').each(function () {
        $(this).children('div:last').addClass('noSeparator');
    });
}

$(function () {
    setTimeout(function () {
        createGalleryView();
        createTipTip();
        SchedulePanelNewStyle();
        if (scrollCenter) {scrollToCenter()}
        if (parent !== self) {iFrameDemand();}
    }, 500);
    pageLoaded = true;
});

