/*
Easy plugin to get element index position
Author: Peerapong Pulpipatnan
http://themeforest.net/user/peerapong
*/

jQuery.fn.getIndex = function () {
    var jQueryp = jQuery(this).parent().children();
    return jQueryp.index(this);
}


jQuery(function () {
    // jQuery("#menu_wrapper").width(jQuery("#main_menu").width());
});

jQuery.fn.setNav = function () {
    jQuery('#main_menu li ul').css({ display: 'none' });

    //	jQuery('#main_menu li').each(function()
    //	{	
    //		
    //		var jQuerysublist = jQuery(this).find('ul:first');
    //		
    //		jQuery(this).hover(function()
    //		{	
    //			jQuerysublist.stop().css({overflow:'hidden', height:'auto', display:'none'}).slideDown(200, function()
    //			{
    //				jQuery(this).css({overflow:'visible', height:'auto'});
    //			});	
    //		},
    //		function()
    //		{	
    //			jQuerysublist.stop().slideUp(200, function()
    //			{	
    //				jQuery(this).css({overflow:'hidden', display:'none'});
    //			});
    //		});	
    //		
    //		jQuery(this).click(function()
    //		{
    //			jQuery(this).children('a').click();
    //		});
    //	});
}

jQuery.fn.pSlider = function (options) {

    settings = jQuery.extend({
        nav: '#slider_nav',
        navWrapper: '.slider_nav_btn',
        fadeSpeed: 800,
        delay: 5000
    }, options);

    var slideWrapper = jQuery(this);
    var slideNav = settings.nav + ' ' + settings.navWrapper;

    jQuery(this).children('div').css({ 'display': 'none' });

    var i = 0;
    jQuery(this).children('div').each(function () {

        if (jQuery(this).attr('id') != 'slider_nav') {
            var slideTitle = jQuery(this).children('span.title').html();
            jQuery(slideNav).append('<a href="javascript:;" rel="' + i + '">' + slideTitle + '</a>');

            if (jQuery(this).children('span.title').children('img').length > 0) {
                jQuery(slideNav).children('a[rel=' + i + ']').css({ 'padding': '6px 15px 0px 15px' });
            }

            i++;
        }
    });

    jQuery(slideNav).children('a').eq(0).addClass('active');
    jQuery(this).children('div').eq(0).css({ 'display': 'block' });

    var it = setInterval(function () {

        if (jQuery(slideNav + ' a.active').next().length > 0) {

            var nextSlide = jQuery(slideNav + ' a.active').next();
            var slideTarget = jQuery(slideNav + ' a.active').next().attr('rel');

            // Remove all active slide
            slideWrapper.children('div').css({ 'display': 'none' });

            if (BrowserDetect.browser != 'Explorer') {
                slideWrapper.children('div').eq(slideTarget).fadeIn(settings.fadeSpeed);
            }
            else {
                slideWrapper.children('div').eq(slideTarget).css({ 'display': 'block' });
            }

            jQuery(settings.nav + ' a').removeClass('active');
            nextSlide.addClass('active');

        }
        else {

            // Remove all active slide
            slideWrapper.children('div').css({ 'display': 'none' });

            if (BrowserDetect.browser != 'Explorer') {
                slideWrapper.children('div').eq(0).fadeIn(settings.fadeSpeed);
            }
            else {
                slideWrapper.children('div').eq(0).css({ 'display': 'block' });
            }

            jQuery(settings.nav + ' a').removeClass('active');
            jQuery(settings.nav + ' a').eq(0).addClass('active');

        }

    }, settings.delay);
    jQuery(slideNav + ' a').click(function () {

        jQuery(settings.nav + ' a').removeClass('active');
        jQuery(this).addClass('active');

        var targetSlide = jQuery(this).attr('rel');

        slideWrapper.children('div').css({ 'display': 'none' });

        if (BrowserDetect.browser != 'Explorer') {
            slideWrapper.children('div').eq(targetSlide).fadeIn(settings.fadeSpeed);
        }
        else {
            slideWrapper.children('div').eq(targetSlide).css({ 'display': 'block' });
        }

        clearInterval(it);

        return false;
    });

    jQuery(slideNav).children('a').eq(0).addClass('active');
    jQuery(this).children('div').eq(0).css({ 'display': 'block' });

}

jQuery(document).ready(function () {

    jQuery(document).setNav();


    jQuery('#content_slider').coinslider({ width: 920, height: 360, opacity: 0.9, navigation: true, titleSpeed: 800, delay: 5000, sDelay: 10 });

    jQuery('#content_slider_slide').pSlider({ nav: '#slider_nav', navWrapper: '.slider_nav_btn', fadeSpeed: 800, delay: 5000 });

    if (jQuery.isFunction(jQuery.fancybox)) {
        jQuery('.portfolio_image').fancybox({
            padding: 10,
            overlayColor: '#fff',
            overlayOpacity: .7
        });

        jQuery('#skins_nav').fancybox({
            padding: 0,
            overlayColor: '#fff',
            overlayOpacity: .7
        });
    }

    /*jQuery.validator.setDefaults({
    submitHandler: function() { 
    var actionUrl = jQuery('#contact_form').attr('action');
		    
    jQuery.ajax({
    type: 'POST',
    url: actionUrl,
    data: jQuery('#contact_form').serialize(),
    success: function(msg){
    jQuery('#contact_form').hide();
    jQuery('#reponse_msg').html(msg);
    }
    });
		    
    return false;
    }
    });
		    
		
    jQuery('#contact_form').validate({
    rules: {
    your_name: "required",
    email: {
    required: true,
    email: true
    },
    message: "required"
    },
    messages: {
    your_name: "Please enter your name",
    email: "Please enter a valid email address",
    agree: "Please enter some message"
    }
    });	
    */
    if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version < 8) {
        var zIndexNumber = 1000;
        jQuery('div').each(function () {
            jQuery(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
        });
    }

    Cufon.replace('.page_caption h1.ru', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '28px'
    });
    Cufon.replace('h1.cufon', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '32px'
    });
    Cufon.replace('h2.cufon', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '28px'
    });
    Cufon.replace('h3.cufon', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '22px'
    });
    Cufon.replace('h4.cufon', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '20px'
    });
    Cufon.replace('h4.cufon_yeniurun', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '16px'
    });
    Cufon.replace('h5.cufon', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '13px'
    });
    Cufon.replace('a.big_button span', {
        textShadow: '0 -1px rgba(0, 0, 0, 0.6)',
        fontSize: '20px'
    });
    Cufon.replace('#footer h2.widgettitle', {
        fontSize: '16px'
    });
    Cufon.replace('.page_caption p', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '16px'
    });
    Cufon.replace('.cs-title strong.header', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '36px'
    });
    Cufon.replace('#content_slider_slide h3', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '36px'
    });
    Cufon.replace('.left_tagline h2', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '22px'
    });
    Cufon.replace('.dropcap1', {
        textShadow: '1px 1px rgba(255, 255, 255, 1)',
        fontSize: '40px'
    });

});
