$(document).ready(function () {

    //fancy 
    $("#request,.testimonials_submit,.request").fancybox({
        'width': 353,
        'height': 416,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'titleShow': false
    });
    $(".vs,.why").fancybox({
        'width': 552,
        'height': 415,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false
    });
    $("a[rel=gallery],a[rel=gallery2],a[rel=gallery3]").fancybox({
        'width': 860,
        'height': 720,
        'showNavArrows': false,
        'cyclic': true,
        'autoScale': false,
        'autoDimensions': false,
        'padding': 0,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titlePosition': 'over',
        'type': 'iframe',
        'titleFormat': function (title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });
    $(".flash").fancybox({
        'type': 'swf',
        'width': 800,
        'height': 600,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false
    });
    $("a.youtube").click(function () {
        $.fancybox({
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'title': this.title,
            'titleShow': false,
            'width': 640,
            'height': 480,
            'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type': 'swf',    // <--add a comma here
            'swf': { 'allowfullscreen': 'true'} // <-- flashvars here
        });
        return false;
    });
    //end fancy

    $(".main_part").css({ 'min-height': $(".left_part").height() });

    function equalHeights(a, b) {
        $(a).height($(b).height());
    }

    $rotator = $('#rotator');

    if ($rotator) {
        count = $('#rotator li').length;

        $('<div id="pagination" class="auto"></div>').appendTo($rotator);

        for (var i = 1, count; i <= count; i++) {
            if (i == 1) {
                $('#pagination').html('<a href="javascript:void(0)" class="cur">' + i + '</a>');
            }
            else {
                $('#pagination').html($('#pagination').html() + '<a href="javascript:void(0)" class="ncur">' + i + '</a>');
            }
        }
        pagination();
        recurs();
    }

    function pagination() {
        $('#pagination a').click(function () {
            $('#pagination a').removeClass('cur');
            $('#pagination').removeClass('auto');
            $('#rotator li').fadeOut(300);
            $(this).addClass('cur');
            sel = $(this).html() - 1;
            $('#rotator li:eq(' + sel + ')').fadeIn(300);
        });
    }

    function recurs() {
        setTimeout(function () { next() }, 5000);
    }

    function next() {
        if ($('#pagination').hasClass('auto')) {
            $c = $('#pagination a.cur').html();
            if ($c == count) {
                $c = 0;
            }

            $('#pagination a:eq(' + $c + ')').click();
            $('#pagination').addClass('auto');
            recurs();
        }
    }

    id = '1';
    $('#taketour').click(function () {
        if (id == '1') {
            id = $('.submenu_hdn');
            id.removeClass('submenu_hdn');
            id.addClass('submenu');
            id = '2';
        }
        else {
            id = $('.submenu');
            id.removeClass('submenu');
            id.addClass('submenu_hdn');
            id = '1';
        }
    });

    $('#taketour_expanded').click(function () {
        if (id == '2') {
            id = $('.submenu_hdn');
            id.removeClass('submenu_hdn');
            id.addClass('submenu');
            id = '1';
        }
        else {
            id = $('.submenu');
            id.removeClass('submenu');
            id.addClass('submenu_hdn');
            id = '2';
        }
    });

    $('#curr').click(function () {
        $(this).find('ul').show();
    });

    $('#curr ul').hover(
	    function () { },
	    function () {
	        $(this).hide();
	    }
    );

    $('#curr ul span').click(function () {
        $('#curr').children('span').html($(this).html()).attr('class', $(this).attr('class'));
        $('#curr ul').hide(1);
        __doPostBack('currency', $('#curr').children('span').html());
    });

    $('.expander_link1').click(function () {
        if ($('.expander1').css('display') == 'none')
            $('.expander1').show();
        else
            $('.expander1').hide();
    });

    $('.expander_link2').click(function () {
        if ($('.expander2').css('display') == 'none')
            $('.expander2').show();
        else
            $('.expander2').hide();
    });

    $('a[href=#top]').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });
    //    var IE6 = false/*@cc_on || @_jscript_version <= 5.7@*/;
    //    if (IE6)
    //        $('form').pngFix();

});

function ShowVh(id) {
    if($('#vh_'+id).is(':hidden')) {
        $('#vh_' + id).slideDown(100);
    }
    else {
        $('#vh_' + id).slideUp(100);
    }
}

function openPopUp(link, height, width) {
    window.open(link, '', 'toolbar=no,menubar=no,scrollbars=1,resizable=1,height=' + height + ',width=' + width + ', top=0,left=' + (screen.availWidth - width - 10));
}

function setCurrency(code) {
    if (code != '') {
        $('#curr').children('span').html($(this).html()).attr('class', code.toLowerCase());
        $('#curr').children('span').html(code.toUpperCase())
    }
}

function isNumberKey(evt) {
    var e = evt
    if (window.event) { // IE
        var charCode = e.keyCode;
    } else if (e.which) { // Safari 4, Firefox 3.0.4
        var charCode = e.which
    }
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function decrease(id) {
    var el = document.getElementById(id);
    var qty = 0;
    if (el != null) {
        qty = el.value;
        if (qty > 1)
            qty--;
        else
            qty = 1;
    }
    el.value = qty;
}

function increase(id) {
    var el = document.getElementById(id);
    var qty = 0;
    if (el != null) {
        qty = el.value;
        if (qty < 100000)
            qty++;
        else
            qty = 1000000;
    }
    el.value = qty;
}

function myShowContent(elts, settings, callback) {
    elts.loading
    .css({
        //marginTop: settings.marginTopLoading+'px',
        marginTop: '0px',
        marginLeft: settings.marginLeftLoading + 'px',
        height: '0px'
    })
    .show()
    .animate
    (
      {
          width: settings.width + 'px'
        , marginLeft: settings.marginLeft + 'px'
      }
      ,
      {
          duration: 10,
          complete: function() {
              elts.loading.animate(
            {
                height: settings.height + 'px'
              , marginTop: settings.marginTop + 'px'
            }
            ,
            {
                duration: 10
              ,
                complete: function() {
                    elts.contentWrapper
                    .css
                    (
                      {
                          width: settings.width + 'px'
                        , height: settings.height + 'px'
                        , marginTop: settings.marginTop + 'px'
                        , marginLeft: settings.marginLeft + 'px'
                      }
                    )
                    .show()
                  ;
                    elts.loading.fadeOut(10, callback);
                }
            }
          );
          }
      }
    );
}

function ValidateForm() {
    var req1 = document.getElementById('txtFirstName');
    var req2 = document.getElementById('txtLastName');
    var req3 = document.getElementById('txtEmailAddress');
    var reg = new RegExp("^[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+(\.[a-z0-9,!#\$%&'\*\+/=\?\^_`\{\|}~-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$");

    if (req1.value == '') {
        alert('Please enter your first name!');
        req1.focus();
        return false;
    }

    if (req2.value == '') {
        alert('Please enter your last name!');
        req2.focus();
        return false;
    }

    if (req3.value == '') {
        alert('Please enter your email address!');
        req3.focus();
        return false;
    }

    if (!req3.value.match(reg)) {
        alert('Please enter valid email address');
        req3.focus();
        return false;
    }

    return true;
}

function OtherFields(id1, id2) {
    var input = document.getElementById(id2);
    if (id1.checked) {
        input.focus();
    } else {
        input.value = '';
    }
}

function MakeChecked(id1, id2) {
    var chb = document.getElementById(id1);
    chb.checked = true;
    OtherFields(id1, id2);
}

function DisableOtherFields(id) {
    var input = document.getElementById(id);
    input.value = '';
}

function uncheck(id, id1) {
    var chb = document.getElementById(id1);
    if (id.checked)
        chb.checked = false;
}

function vs() {
    $.fancybox({
        'href': '#vs',
        'width': 552,
        'height': 415,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false
    });
}

function why() {
    $.fancybox({
        'href': '#why',
        'width': 552,
        'height': 415,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'titleShow': false
    });
}
