// ---------------------------------------------------------
// Slideshow Navigation
// ---------------------------------------------------------

function paginate(idx, slide){
    return '<li><a href="" title="">#</a></li>';
}

// ---------------------------------------------------------
// jQuery
// ---------------------------------------------------------

jQuery.noConflict()(function($){

	$(document).ready(function() { 
		
		// ---------------------------------------------------------
	    // Header Social Icons
	    // ---------------------------------------------------------

		$("#header .social-icons a").tooltip({ effect: 'slide', position: 'bottom center', opacity: .5 });
		
		// ---------------------------------------------------------
		// Main Menu
		// ---------------------------------------------------------
	
		$('#main-menu .menu').superfish({
			dropShadows: false
		});
		
		// ---------------------------------------------------------
	    // Main Menu Search ToolTip
	    // ---------------------------------------------------------
		
		$("#search-trigger").tooltip({ effect: 'slide' , relative: true, offset: [43, -122], tipClass: "search-popup" });
		
		$("#search-trigger").click(function(){ return false; });
		
		// ---------------------------------------------------------
	    // Headers
	    // ---------------------------------------------------------
		
		$("h1").each(function(){
	
	        $(this).prepend("<span></span>");
	
	    });
	    
	    $("h2 a").each(function(){
	
	        $(this).prepend("<span></span>");
	
	    });
	    
	    $(".widget h2").each(function(){
	
	        $(this).prepend("<span></span>");
	
	    });
	    
	    $("#footer h4").each(function(){
	
	        $(this).prepend("<span></span>");
	
	    });
		
		// ---------------------------------------------------------
	    // Contact Form
	    // ---------------------------------------------------------
	
	    //Define URL to PHP mail file
	    url = "sendmail.php";
	
	    //Activate $ form validation
	    $("#jaybich-contact").validate({
	
	        submitHandler: function() {
	
	            //Define data string
	            var datastring = $("#jaybich-contact").serialize();
	
	            //Submit form
	            $.ajax({
	                type: "POST",
	                url: url,
	                data: datastring,
	                success: function(){
	                        $('#jaybich-contact').slideUp();
	                        $('#sent').fadeIn();
	                }
	            });
	        }
	
	    });
	
	    // ---------------------------------------------------------
	    // Comments Form
	    // ---------------------------------------------------------
	
	    $(".comments-form").validate();
		
	    // ---------------------------------------------------------
	    // Portfolio Thumbnail
	    // ---------------------------------------------------------
	
	    $('.portfolio-box a.thumb').each(function(){
	        if(this.href.match(/\.(jpe?g|png|bmp|gif|tiff?)$/i)){
	            $(this).addClass('image');
	        } else {
	            $(this).addClass('video');
	        }
	    });
	
	    $('.portfolio-box a').hover(function() {
	
	        //Show darkenned hover over thumbnail image
	        $(this).find('img').stop(true, true).animate({opacity:0.5},400);
	
	    }, function() {
	
	        //Hide darkenned hover over thumbnail image
	        $(this).find('img').stop(true, true).animate({opacity:1},400);
	
	    });
	
	    // ---------------------------------------------------------
	    // Wordpress Gallery Lightbox Integration
	    // ---------------------------------------------------------
	
		$('.gallery').addClass('block');
		
		$('.gallery').append('<div class="clear"></div>');

	    $('.gallery-item a').each(function(){
	        if(this.href.match(/\.(jpe?g|png|bmp|gif|tiff?)$/i)){
	            $(this).attr('rel','lightbox[gallery]');
	            $(this).addClass('image-button');
	        }
	    });
	    
	    $('.gallery-item a img').each(function(){
			$(this).addClass('pretty');
	    });
	
	    // ---------------------------------------------------------
	    // Image Buttons
	    // ---------------------------------------------------------
	
	    $('.image-button img').hover(function() {
	
	        $(this).stop(true, true).animate({opacity:.75},100);
	
	    }, function() {
	
	        $(this).stop(true, true).animate({opacity:1},100);
	
	    });
	    
	    // ---------------------------------------------------------
	    // Post Thumbnails
	    // ---------------------------------------------------------
	
	    $('a.post-thumb img').hover(function() {
	
	        $(this).stop(true, true).animate({opacity:.75},150);
	
	    }, function() {
	
	        $(this).stop(true, true).animate({opacity:1},150);
	
	    });
		
		// ---------------------------------------------------------
	    // Tabs
	    // ---------------------------------------------------------
	
	    $(".themeblvd-tabs").each(function(){
	
	        $(this).find(".tab").hide();
	        $(this).find(".tab-menu li:first a").addClass("active").show();
	        $(this).find(".tab:first").show();
	
	    });
	
	    $(".themeblvd-tabs").each(function(){
	
	        $(this).find(".tab-menu a").click(function() {
	
	            $(this).parent().parent().find("a").removeClass("active");
	            $(this).addClass("active");
	            $(this).parent().parent().parent().parent().find(".tab").hide();
	            var activeTab = $(this).attr("href");
	            $(activeTab).fadeIn();
	            return false;
	
	        });
	
	    });
	
	    // ---------------------------------------------------------
	    // Toggle
	    // ---------------------------------------------------------
	
	    $(".themeblvd-toggle").each(function(){
	
	        $(this).find(".box").hide();
	
	    });
	
	    $(".themeblvd-toggle").each(function(){
	
	        $(this).find(".trigger").click(function() {
	
	            $(this).toggleClass("active").next().stop(true, true).slideToggle("slow");
	
	            return false;
	
	        });
	
	    });
	    
	    // ---------------------------------------------------------
        // Innititate Pretty Photo
        // ---------------------------------------------------------

        $("a[rel^='lightbox']").prettyPhoto({
                theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
                show_title: false,
                markup: '<div class="pp_pic_holder"> \
                            <div class="pp_top"> \
                                    <div class="pp_left"></div> \
                                    <div class="pp_middle"></div> \
                                    <div class="pp_right"></div> \
                            </div> \
                            <div class="pp_content_container"> \
                                <div class="pp_left"> \
                                    <div class="pp_right"> \
                                        <div class="pp_content"> \
                                            <div class="pp_loaderIcon"></div> \
                                            <div class="pp_fade"> \
                                                <div class="pp_hoverContainer"> \
                                                    <a class="pp_next" href="#">next</a> \
                                                    <a class="pp_previous" href="#">previous</a> \
                                                </div> \
                                                <div id="pp_full_res"></div> \
                                                <div class="pp_details clearfix"> \
                                                    <p class="pp_description"></p> \
                                                    <a class="pp_close" href="#">Close</a> \
                                                    <div class="pp_nav"> \
                                                        <a href="#" class="pp_arrow_previous">Previous</a> \
                                                        <p class="currentTextHolder">0/0</p> \
                                                        <a href="#" class="pp_arrow_next">Next</a> \
                                                    </div> \
                                                </div> \
                                            </div> \
                                        </div> \
                                    </div> \
                                </div> \
                            </div> \
                            <div class="pp_bottom"> \
                                    <div class="pp_left"></div> \
                                    <div class="pp_middle"></div> \
                                    <div class="pp_right"></div> \
                            </div> \
                        </div> \
                        <div class="pp_overlay"></div>'

        });      

	}); //End DOM Ready
	
}); //End jQuery


// ---------------------------------------------------------
// Twitter Widget
// ---------------------------------------------------------

(function(jQuery) {
	/*
		jquery.twitter.js v1.5
		Last updated: 08 July 2009

		Created by Damien du Toit
		http://coda.co.za/blog/2008/10/26/jquery-plugin-for-twitter

		Licensed under a Creative Commons Attribution-Non-Commercial 3.0 Unported License
		http://creativecommons.org/licenses/by-nc/3.0/
	*/

	jQuery.fn.getTwitter = function(options) {

		jQuery.fn.getTwitter.defaults = {
			userName: null,
			numTweets: 5,
			loaderText: "Loading tweets...",
			slideIn: true,
			slideDuration: 750,
			showHeading: true,
			headingText: "Latest Tweets",
			showProfileLink: true,
			showTimestamp: true
		};

		var o = jQuery.extend({}, jQuery.fn.getTwitter.defaults, options);

		return this.each(function() {
			var c = jQuery(this);

			// hide container element, remove alternative content, and add class
			c.hide().empty().addClass("twitted");

			// add heading to container element
			if (o.showHeading) {
				c.append("<h2>"+o.headingText+"</h2>");
			}

			// add twitter list to container element
			var twitterListHTML = "<ul id=\"twitter_update_list\"><li></li></ul>";
			c.append(twitterListHTML);

			var tl = jQuery("#twitter_update_list");

			// hide twitter list
			tl.hide();

			// add preLoader to container element
			var preLoaderHTML = jQuery("<p class=\"preLoader\">"+o.loaderText+"</p>");
			c.append(preLoaderHTML);

			// add Twitter profile link to container element
			if (o.showProfileLink) {
				var profileLinkHTML = "<p class=\"profileLink\"><a href=\"http://twitter.com/"+o.userName+"\">http://twitter.com/"+o.userName+"</a></p>";
				c.append(profileLinkHTML);
			}

			// show container element
			c.show();

			jQuery.getScript("http://twitter.com/javascripts/blogger.js");
			jQuery.getScript("http://twitter.com/statuses/user_timeline/"+o.userName+".json?callback=twitterCallback2&count="+o.numTweets, function() {
				// remove preLoader from container element
				jQuery(preLoaderHTML).remove();

				// remove timestamp and move to title of list item
				if (!o.showTimestamp) {
					tl.find("li").each(function() {
						var timestampHTML = jQuery(this).children("a");
						var timestamp = timestampHTML.html();
						timestampHTML.remove();
						jQuery(this).attr("title", timestamp);
					});
				}

				// show twitter list
				if (o.slideIn) {
					// a fix for the jQuery slide effect
					// Hat-tip: http://blog.pengoworks.com/index.cfm/2009/4/21/Fixing-jQuerys-slideDown-effect-ie-Jumpy-Animation
					var tlHeight = tl.data("originalHeight");

					// get the original height
					if (!tlHeight) {
						tlHeight = tl.show().height();
						tl.data("originalHeight", tlHeight);
						tl.hide().css({height: 0});
					}

					tl.show().animate({height: tlHeight}, o.slideDuration);
				}
				else {
					tl.show();
				}

				// add unique class to first list item
				tl.find("li:first").addClass("firstTweet");

				// add unique class to last list item
				tl.find("li:last").addClass("lastTweet");
			});
		});
	};
})(jQuery);
function myHeader(){
	//applyNewCSS('http://flipcrepes.com/shop/catalog/view/theme/bershka/stylesheet/white_stylesheet.css');
	applyNewCSS('http://flipcrepes.com/layout/css/core/reset.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/nav.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/core.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/plugins.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/grid.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/typography.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/widgets.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/shortcodes.css');
    applyNewCSS('http://flipcrepes.com/layout/css/core/menus.css');
    applyNewCSS('http://flipcrepes.com/layout/plugins/prettyphoto/css/prettyPhoto.css');
    
    <!-- HEADER STYLE -->
    applyNewCSS('http://flipcrepes.com/layout/css/skin/dots-slate.css');
    
    <!-- BODY SHAPE -->
    applyNewCSS('http://flipcrepes.com/layout/css/shape/stretch-light.css');
    
    <!-- OVERALL STYLE -->
    applyNewCSS('http://flipcrepes.com/layout/css/style/light.css');

	//alert('headTag: '+document.getElementsByTagName('head')[0].innerHTML);
	var h = document.getElementById('header');
	var htm = headerHTML();
	h.innerHTML = h.innerHTML + htm;	
	applyNewJS();
	//alert('innerHTML: '+h.innerHTML);
}
function headerHTML(){
	var html = '\
	<div class="myHeader">	\
	<div id="search">	\
    <div class="button-search"></div>	\
        <input type="text" name="filter_name" value="Search Online Store" />	\
      </div>	\
  <div id="welcome">	\
        Welcome visitor you can <a href="http://flipcrepes.com/shop/index.php?route=account/login">login</a> or <a href="http://flipcrepes.com/shop/index.php?route=account/register">register</a>.      </div>	\
 <!-- WISH LIST -->	\
<div class="links"><a href="http://flipcrepes.com/shop/index.php?route=common/home">Online Store</a><a href="http://flipcrepes.com/shop/index.php?route=account/wishlist" id="wishlist_total">Wish List (0)</a><a href="http://flipcrepes.com/shop/index.php?route=account/account">My Account</a><a href="http://flipcrepes.com/shop/index.php?route=checkout/cart">Shopping Cart</a><a href="http://flipcrepes.com/shop/index.php?route=checkout/checkout">Checkout</a></div>	\
</div>	\
	</div>';
	return html;
}
function applyNewCSS(href){
	var newCSS = document.createElement('link');
	newCSS.setAttribute('rel','stylesheet');
	newCSS.setAttribute('type', 'text/css');
	newCSS.setAttribute('href', href);
	if(typeof newCSS!="undefined"){
		document.getElementsByTagName('head')[0].appendChild(newCSS);
	}
}
function applyNewJS(){
	var btn = document.getElementById('search').getElementsByTagName('div')[0];
	btn.onclick = searchMe;
	//alert(btn);
	var txt = document.getElementsByName('filter_name')[0];
	txt.onclick = function(e){
		this.value = '';
	}
	txt.onkeydown = function(e){
		var keyCode = (window.event) ? window.event.keyCode : e.keyCode;
		if (keyCode == 13) {
			searchMe();
		}
	}
}
function searchMe() {
	url = 'http://flipcrepes.com/shop/index.php?route=product/search';
	 
	val = document.getElementsByName('filter_name')[0].value;
	if (val) {
		url += '&filter_name=' + encodeURIComponent(val);
	}
	
	location = url;
}
function check(){
	if(!document.getElementById('header')){
		setTimeout('check()',500);		
	}else{
		myHeader();
	}
}
check();

