$(document).ready(function() {

    if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
        $('#contact-us').click(function() {
            var $address = $('#contact-us-address');
            if ($address.css('display') == "none") {
                $address.toggle('slide',{direction: 'left'}, 750);
            } else {
                $address.toggle('slide',{direction: 'left'}, 750);
            }
        });
    } else {
        $('#contact-us').live('click', function() {
            var $address = $('#contact-us-address');
            if ($address.css('display') == "none") {
                $address.toggle('slide',{direction: 'left'}, 750);
            } else {
                $address.toggle('slide',{direction: 'left'}, 750);
            }
        });
    }
    
    $('#slider').easySlider({
        prevText: '',
        nextText: '',
        continuous : false,
        firstId: 'news',
        firstText: 'Back to start',
        firstShow: true
        /*continuous: true*/
    });
    
    $('span#news').live('click', function() {
        var $holder = $('.dynamic-text-div ul');
        $('#news-holder span.text-left').show();
        $holder.stop().animate({
            'top': '0px'
        },{
            queue: true,
            duration: 1000
        });
    })
   
    $('#nextBtn a').live('click', function() {
        var $holder = $('.dynamic-text-div ul');
        var $lis = $('.dynamic-text-div ul li');
        $('#news-holder span.text-left').hide();
        if ($lis.length <= "1") {
            return true;
        } else {
            if ($holder.css('top') == '1145px') {
                return true;
            } else {
                $holder.animate({
                    'top': '-=190px'
                }, {
                    queue: true,
                    duration: 750
                });
            }
            return false;
        }
    });
   
    $('#prevBtn a').live('click', function() {
        var $holder = $('.dynamic-text-div ul');
        var $lis = $('.dynamic-text-div ul li');
        if ($('span#prevBtn a').css('display') == "none") {
            $('#news-holder span.text-left').show();
        }
        if ($lis.length <= "1") {
            return true;
        } else {
            if ($holder.css('top') == '0px') {
                return true;
            } else {
                $holder.stop().animate({
                    'top': '+=190px'
                }, {
                    queue: true,
                    duration: 750
                });
            }
            return false;
        }
   });
   
   $('#slider li a').fancybox({
                                'padding' : 10,
                                'margin': 5,
                                'scrolling': 'no',
                                'autoScale' : true,
                                'transitionIn' : 'fade',
                                'transitionOut' : 'fade'
                                });
                                
   
   $('#li_9_lightbox, #li_9 span.play-button').live('click', function() {
       $.fancybox([ {
                        'href':'img/lightbox/u1.jpg'
                    },
                    {
                        'href':'img/lightbox/u2.jpg'
                    },
                    {
                        'href':'img/lightbox/u3.jpg'
                    }
                ],
                {
                    'padding' : 10,
                    'margin': 5,
                    'scrolling': 'no',
                    'autoScale' : true,
                    'transitionIn' : 'fade',
                    'transitionOut' : 'fade'
            });
       return false;
   });
   
   $('#li_2_lightbox, #li_2 span.play-button').live('click', function() {
       $.fancybox([ {
                        'href':'img/lightbox/ma5.jpg'
                    },
                    {
                        'href':'img/lightbox/ma6.jpg'
                    },
                    {
                        'href':'img/lightbox/ma7.jpg'
                    },
                    {
                        'href':'img/lightbox/ma8.jpg'
                    } ],
                    {
                        'padding' : 10,
                        'margin': 5,
                        'scrolling': 'no',
                        'autoScale' : true,
                        'transitionIn' : 'fade',
                        'transitionOut' : 'fade'
                    }
                );
       return false;
   });
   
   $('#li_4_lightbox, #li_4 span.play-button').live('click', function() {
       $.fancybox([ {
                        'href':'img/lightbox/qms1.jpg'
                    },
                    {
                        'href':'img/lightbox/qms2.jpg'
                    },
                    {
                        'href':'img/lightbox/qms3.jpg'
                    },
                    {
                        'href':'img/lightbox/qms4.jpg'
                    }
                ],
                {
                    'padding' : 10,
                    'margin': 5,
                    'scrolling': 'no',
                    'autoScale' : true,
                    'transitionIn' : 'fade',
                    'transitionOut' : 'fade'
            });
       return false;
   });
   
   $('#li_5_lightbox, #li_5 span.play-button').live('click', function() {
       $.fancybox([ {
                        'href':'img/lightbox/vs1.jpg'
                    },
                    {
                        'href':'img/lightbox/vs2.jpg'
                    }
                ],
                {
                    'padding' : 10,
                    'margin': 5,
                    'scrolling': 'no',
                    'autoScale' : true,
                    'transitionIn' : 'fade',
                    'transitionOut' : 'fade'
            });
       return false;
   });
   
   $('#li_7_lightbox, #li_7 span.play-button').live('click', function() {
       $.fancybox([ {
                        'href':'img/lightbox/ph3.jpg'
                    },
                    {
                        'href':'img/lightbox/ph2.jpg'
                    },
                    {
                        'href':'img/lightbox/ph1.jpg'
                    },
                    {
                        'href':'img/lightbox/ph4.jpg'
                    }
                ],
                {
                    'padding' : 10,
                    'margin': 5,
                    'scrolling': 'no',
                    'autoScale' : true,
                    'transitionIn' : 'fade',
                    'transitionOut' : 'fade'
            });
       return false;
   });
   
    
   
   $('#screen li').live('click', function() {
       var openDiv = $(this).attr('id');
       var lightBoxDiv = openDiv+'_lightbox'
       $('#'+lightBoxDiv).show();
   });
   
    /*   Footer Image swap over  */
    $('#footer li img').live('mouseover mouseout', function(evt) {
        var $hoverDiv = $(this).closest('li').find('.footerhoveropen');
        var $upArrow = $(this).closest('li').find('.uparrow');
        if(evt.type == "mouseover") {
            var imgsrc = $(this).attr('src');
            imgsrc = imgsrc.split('.');
            var newImage = imgsrc[0]+'_hover';
            var ext = imgsrc[1];
            var imgWidth = this.width;
            var midWay = Math.round(imgWidth/2);
            midWay = (midWay-5);
            $(this).attr({'src': newImage+'.'+ext});
            $upArrow.css({'left': midWay+'px'});     
            $hoverDiv.slideDown('500', function(){
                $('.footerhoveropen').mouseenter(function(){
                    if($(this).hover()) {
                        $hoverDiv.stop();
                        $(this).css({'height': '55px'});
                    }
                });
                $('.footerhoveropen').mouseleave(function(){
                    $hoverDiv.slideUp('500', function() {
                        $(this).css({'height': '55px;'});
                    });
                });
            });
        } else {
            var backimgsrc = $(this).attr('src');
            var origimageName = backimgsrc.replace('_hover', '');
            $(this).attr({'src': origimageName});
            $hoverDiv.slideUp('500', function() {
                $(this).css({'height': '55px;'})
            });
        }
    });
     
});


