/*
* Droppy 0.1.2
* (c) 2008 Jason Frame (jason@onehackoranother.com)
*/

$.fn.droppy = function(options) {

    options = $.extend({ speed: 250 }, options || {});

    this.each(function() {

        var root = this, zIndex = 1000;

        function getSubnav(ele) {
            if (ele.nodeName.toLowerCase() == 'li') {
                var subnav = $('> ul', ele);
                return subnav.length ? subnav[0] : null;
            } else {
                return ele;
            }
        }

        function getActuator(ele) {
            if (ele.nodeName.toLowerCase() == 'ul') {
                return $(ele).parents('li')[0];
            } else {
                return ele;
            }
        }

        function hide() {
            var subnav = getSubnav(this);
            if (!subnav) return;
            $.data(subnav, 'cancelHide', false);
            setTimeout(function() {
                if (!$.data(subnav, 'cancelHide')) {
                    $(subnav).slideUp(options.speed);
                }
            }, 50);
        }

        function show() {
            var subnav = getSubnav(this);
            if (!subnav) return;
            $.data(subnav, 'cancelHide', true);
            $(subnav).css({ zIndex: zIndex++ }).slideDown(options.speed);
            if (this.nodeName.toLowerCase() == 'ul') {
                var li = getActuator(this);
                $(li).addClass('hover');
                $('> a', li).addClass('hover');
            }
        }

        $('ul, li', this).hover(show, hide);
        $('li', this).hover(
      function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
      function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
    );

    });

    //  Animate main logo

    $('#posim_logo').mouseover(function() {
        $("#posim_logo").animate({ opacity: .75 }, 100, function() {
            $("#posim_logo").animate({ opacity: 1 }, 600)
        });
    });

    //  Preload images

    jQuery.preloadImages = function() {
        for (var i = 0; i < arguments.length; i++) {
            jQuery("<img>").attr("src", arguments[i]);
        }
    }

    // preloaded images array

    //$.preloadImages("/store/pc/template/products_btn_over.png", "/store/pc/template/services_btn_over.png", "/store/pc/template/support_btn_over.png",
	//								"/store/pc/template/demo_btn_over.png", "/store/pc/template/chat_btn_over.png", "/store/pc/template/training_btn_over.png",
	//								"/store/pc/template/users_btn_over.png", "/store/pc/template/store_btn_over.png");

    //

    $(".noclick").click(function() {
        return false;
    });

    $(".noclick").mouseover(function() {
        $(this).css({ 'cursor': 'default' });
    });

    //////////////  navigation hover

    // products

    $("#shop").hover(
		function() {
    $("#shop img").attr({ src: '/store/pc/template/shop.png' });
		},
      function() {
          $("#shop img").attr({ src: '/store/pc/template/shop.png' });
      }
	);

    //services

    $("#participate").hover(
		function() {
    $("#participate img").attr({ src: '/store/pc/template/participate.png' });
		},
      function() {
		$("#participate img").attr({ src: '/store/pc/template/participate.png' });
      }
	);

    //support

      $("#services").hover(
		function() {
      $("#services img").attr({ src: '/store/pc/template/services.png' });
		},
      function() {
		$("#services img").attr({ src: '/store/pc/template/services.png' });
      }
	);

    //training

      $("#about_us").hover(
		function() {
      $("#about_us img").attr({ src: '/store/pc/template/about_us.png' });
		},
      function() {
		$("#about_us img").attr({ src: '/store/pc/template/about_us.png' });
      }
	);

    //users

      $("#my_account").hover(
		function() {
      $("#my_account img").attr({ src: '/store/pc/template/my_account.png' });
		},
      function() {
		$("#my_account img").attr({ src: '/store/pc/template/my_account.png' });
      }
	);

    //store

    $("#store").hover(
		function() {
		    $("#store img").attr({ src: '/store/pc/template/store_btn_over.png' });
		},
      function() {
          $("#store img").attr({ src: '/store/pc/template/store_btn.png' });
      }
	);

    //chat

    $("#chat").hover(
		function() {
		    $("#chat img").attr({ src: '/store/pc/template/chat_btn_over.png' });
		},
      function() {
          $("#chat img").attr({ src: '/store/pc/template/chat_btn.png' });
      }
	);

    //demo

    $("#demo").hover(
		function() {
		    $("#demo img").attr({ src: '/store/pc/template/demo_btn_over.png' });
		},
      function() {
          $("#demo img").attr({ src: '/store/pc/template/demo_btn.png' });
      }
	);

};   //


//navigation image swap functions

function imageOver(image_source, image) {
    $(image).attr({ src: image_source });

}

function imageOut(image_source, image) {
    $(image).attr({ src: image_source });
}
